0
Django的1.10發展Django的STATIC_URL只有工作沒有斜線
使用的runserver出於某種原因,沒有文件可以在我的靜態目錄中找到,除非我把它列爲例如:
STATIC_URL = 'static/'
if not os.environ.get('DEPLOYED'):
STATIC_ROOT = os.path.join(BASE_DIR, "static/")
但所有文檔和我之前做的所有事情都說它應該是/ static /這讓我覺得我在其他地方做錯了什麼。我使用Django的runserver命令
URLS:
if settings.DEBUG:
from django.conf.urls.static import static
from django.contrib.staticfiles import views
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
我到現在網站通過鍵入本地主機:8000 /靜態/ index.html的
你不需要手動添加靜態url到你的urlpatterns。這是自動完成的:https://docs.djangoproject.com/en/1.10/howto/static-files/#configuring-static-files - 「在開發過程中,如果你使用django.contrib.staticfiles,這將自動完成通過runserver當DEBUG設置爲True「 –
我現在看到這個。但是,如果我從urls.py中移除urlpattern行並將STATIC_URL設置爲/ static /或static /,則不起作用。然而,它的工作原理如上所示。我得到的錯誤是'index.html'無法找到使用相同的地址 – Diesel
它應該工作。嘗試findstatic命令:https://docs.djangoproject.com/en/1.10/ref/contrib/staticfiles/#findstatic用「--verbosity 2」來查看實際搜索的文件路徑。 –