为什么Django只提供包含空格的文件?

flu*_*els 1 python django

我正在编写一个基本的Django应用程序.出于测试/开发的目的,我正在尝试使用Django的开发服务器来提供网站的静态内容,如http://docs.djangoproject.com/en/dev/howto/static-files/#howto-static-files.

我的urls.py包含:

    (r'^admin/(.*)', admin.site.root),

    (r'^(?P<page_name>\S*)$', 'Blah.content.views.index'),

    (r'^static/(?P<path>.*)$', 'django.views.static.serve',
        {'document_root': 'C:/Users/My User/workspace/Blah/media',
         'show_indexes': True})
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试访问一个文件,如http:// localhost:8000/static/images/Logo.jpg Django给了我一个404错误,声称"没有页面匹配给定的查询".

当我尝试访问一个文件,如http:// localhost:8000/static/images/Blah%20Logo.jpg时,它会提供文件!

这是怎么回事?

Ale*_*lev 10

你有错误的模式订单urls.py.

当您尝试检索没有空格的路径时,它匹配:

(r'^(?P<page_name>\S*)$', 'Blah.content.views.index'),
Run Code Online (Sandbox Code Playgroud)

不是static.serve,当然你没有这样的页面,但当你尝试访问带有空间的路径时,它匹配正确的static.serve模式,因为它更通用并允许空格.

要解决这个问题,只需交换这些模式.