我无法让我的网站正确加载静态文件。
关于静态文件的settings.py文件如下:
# Static files
STATIC_URL = '/static/'
STATIC_ROOT = '/var/www/str8red.com/static/'
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
当我运行以下命令时:
python manage.py collectstatic
我得到以下结果:
1858 static files copied to '/var/www/str8red.com/static'
当我检查目录时,一切似乎都工作正常。
然后我去网上查看我的网站:“https://str8red.com/ https://str8red.com/" 并且所有 css 或图像都不起作用。我在 chrome 开发者模式中看到的错误示例如下:
GET https://str8red.com/static/str8RED.png 404 (Not Found)
使用以下代码抓取文件:
{% load staticfiles %}
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="{% url 'index' %}">
<img src="{% static 'str8RED.png' %}" width="97" height="22" alt="str8RED.com" />
</a>
网址文件:
from django.conf.urls import include, url
from django.contrib import admin
from django.views.static import serve
from dwad import settings
urlpatterns = [
url(r'', include('meta.urls')),
url(r'^straightred/', include('straightred.urls')),
url(r'^admin/', include(admin.site.urls)),
url(r'^chaining/', include('smart_selects.urls')),
url(r'^tinymce/', include('tinymce.urls')),
url(r'^accounts/', include('allauth.urls')),
]
# Get Django to serve media files in debug mode.
if settings.DEBUG:
urlpatterns += [url(r'^resources/(?P<path>.*)$', serve, {'document_root': settings.MEDIA_ROOT})]
非常感谢任何帮助,非常感谢,艾伦。