【发布时间】:2011-11-10 13:48:28
【问题描述】:
我已经像这样配置了我的静态设置:
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()
它非常适用于 url localhost:8000/login,但是当我到达由我的 profiles 应用程序处理的 localhost:8000/profile/edit 站点时,{{ STATIC_URL }} 将所有路径从 /static/... 更改为 @987654330 @,所以我的 javascripts 和样式表已经找不到了。
我做错了什么?
编辑:这是我的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,在开发环境中提供静态文件是必需的。
-
如您提供的链接中所述,这仅在您不使用 django 内置服务器时有效。否则,将自动提供静态文件。您使用的是哪个服务器?
-
你能举个例子说明你在个人资料模板上有 {{ STATIC_URL }} 的地方吗?
-
@Thibault J:是的,我只是在开发过程中使用
manage.py runserver。 @Jordan:已编辑问题。
标签: python django django-staticfiles