7
votes

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

2

2 Answers

5
votes

I found that, by default, django 'runserver' itself, preempts /static/ urls : even with custom middleware, you cannot force django to point '/static/' to your code.

The only solution I found : use --nostatic option for './manage.py runserver', then one can use his own url patterns and views in order to serve static files.

0
votes

Set DEBUG to False. Django only serves static files when it's True.