7

I am beginning to use the application 'django.contrib.staticfiles' to collect static files into the /static/ directory of my project.

The problem is that, when I am using the django development server (manage.py runserver) it automatically serve static files.

It is usually fine, but in my case, I would like to serve these static files myself.

I would like to put in the urls.py file something like that :

urlpatterns += patterns('',
        url('^static/(?P<path>.*)$', myStaticMediaServe,{'document_root': settings.STATIC_ROOT ,'show_indexes': True}),
        )

The problem is that 'django.contrib.staticfiles' application has got the priority on '/static/' url when settings.DEBUG=True : I cannot find a way to make Django use my '/static/' urlpattern description while being in debug mode

If I remove 'django.contrib.staticfiles' from settings.py : my '/static/' urlpattern works but I loose static files collecting.

Do you have an idea to use 'django.contrib.staticfiles' AND use my own static files server through an urlpattern description AND have settins.DEBUG=True

4

2 回答 2

5

我发现,默认情况下,django 'runserver' 本身会抢占 /static/ urls :即使使用自定义中间件,您也不能强制 django 将 '/static/' 指向您的代码。

我发现的唯一解决方案是:对 './manage.py runserver' 使用 --nostatic 选项,然后可以使用他自己的 url 模式和视图来提供静态文件。

于 2012-05-29T22:15:48.413 回答
0

设置DEBUGFalse。Django 仅在True.

于 2012-05-29T16:53:29.877 回答