0
我已經從1.9.6升級到Django 1.10。下面是以前工作我的urls.py文件:Django升級:不提供靜態文件
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})]
if not settings.DEBUG:
urlpatterns += [
url(r'^resources/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
url(r'^static/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.STATIC_ROOT}),
]
當嘗試運行網站獲得:
view must be a callable or a list/tuple in the case of include().
我知道上面的錯誤是由於「django.views.static。服務於'字符串。如果我從字符串和鏈接刪除他們實際的視圖我得到以下錯誤:
name 'django' is not defined
如果我刪除一切從「獲取的Django服務在調試模式下的媒體文件。」並低於站點負載,但不提供靜態或媒體文件。這顯然意味着沒有應用CSS並且沒有加載圖像。
如果人們可以提供一些建議,下一步將不勝感激。
可能有用的一些設置:
# Static files
STATIC_URL = '/static/'
STATIC_ROOT = '/var/www/str8red.com/static/'
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
MEDIA_URL = '/resources/'
MEDIA_ROOT = 'media' if DEBUG else '/var/www/str8red.com/resources/'
感謝迅速的迴應。我得到了以上錯誤與上述「名稱」靜態「未定義」 –
從django.conf.utils.urls導入靜態,更新代碼 – zaidfazil
好消息是,該網站加載,但仍然沒有圖像或css正在服務。您是否需要查看我的任何設置? –