1

我的 urls.py 中有以下内容

if settings.DEBUG:
    urlpatterns += patterns('',
        (r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.STATIC_ROOT, 'show_indexes': True}),
    )

它不起作用。我总是得到'filename.txt' could not be found 如果我将 URL 从更改r'^static/(?P<path>.*)$'为其他任何内容,例如r'^staticabc/(?P<path>.*)$'它可以工作。

知道如何使此 URL 正常工作吗?

4

1 回答 1

1

见:https ://docs.djangoproject.com/en/dev/howto/static-files/#configuring-static-files

在“提供文件”信息框中,它说明如果DEBUG = True.

它使用的版本从您发现的位置提供静态文件STATICFILES_FINDERS

您提供的额外定义会覆盖此定义,并且仅提供来自 的文件STATIC_ROOT,除非您刚刚运行,否则这些文件collectstatic将为空。

于 2013-08-06T00:56:36.013 回答