我已經配置,像這樣我的靜態設置:Django的:STATIC_URL增加了應用程序的名字到url
STATIC_ROOT = os.path.join(SITE_ROOT, 'static')
STATIC_URL = '/static/'
STATICFILES_DIRS = (
('js', os.path.join(STATIC_ROOT, 'js')),
('css', os.path.join(STATIC_ROOT, 'css')),
)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
而這些在我urls.py
:
urlpatterns = patterns('',
url(r'^login/?$', login, name='login'),
url(r'^logout/?$', logout_then_login, name='logout'),
url(r'^profile/(?P<user_id>\d+)$', 'profiles.views.detail'),
url(r'^profile/edit$', 'profiles.views.edit'),
)
urlpatterns += staticfiles_urlpatterns()
它非常適用於網址localhost:8000/login
,但當我到達localhost:8000/profile/edit
網站(由我的profiles
應用處理)時,{{ STATIC_URL }}
將所有路徑從/static/...
更改爲/profile/static/...
,因此我的JavaScript和樣式表不是找到了更多。
我做錯了什麼?
編輯:這將是我base.html
<!DOCTYPE html>
<html>
<head>
<title>Neighr{% block title %}{% endblock %}</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<script type="text/javascript" src="{{ STATIC_URL }}js/jquery.min.js"></script>
{% block script %}{% endblock %}
</head>
<body>
{% block content %}{% endblock %}
</body>
</html>
'staticfiles_urlpatterns()'?它是什麼? –
@ Thibault J:根據[this](https://docs.djangoproject.com/en/dev/howto/static-files/#serving-static-files-in-development),爲靜態文件提供服務在開發環境中。 – Lanbo
正如你給出的鏈接所述,這隻有在你不使用django內置服務器時纔有效。否則,靜態文件將自動提供。你在使用哪臺服務器? –