2

I have configured my static settings like so:

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',
)

and these in my 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()

It works very well for the url localhost:8000/login, but when I get to the localhost:8000/profile/edit site, which is handled by my profiles App, the {{ STATIC_URL }} changes all the paths from /static/... to /profile/static/..., so my javascripts and stylesheets are not found any more.

What'd I do wrong?

EDIT: Here would be my 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>
4

1 回答 1

3

由于您使用的是 django 内置开发服务器,请尝试从您的以下行中删除urls.py

urlpatterns += staticfiles_urlpatterns()

在生产中,你最好不要用 django 提供静态文件,所以使用collectstatic命令。

编辑

如果settings.py,尝试这样的事情:

STATIC_ROOT = os.path.join(os.path.dirname(__file__), '../../static')
STATIC_URL = '/static/'
于 2011-09-06T08:31:12.383 回答