How to override django static development server?

I am starting to use the django.contrib.staticfiles application to collect static files in the / static / directory of my project.

The problem is that when I use the django development server (manage.py runningerver), it automatically serves static files.

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

I would like to add something like this to the urls.py file:

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

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

If I remove 'django.contrib.staticfiles' from settings.py: my '/ static /' urlpattern works, but I lose the collection of static files.

You have an idea to use 'django.contrib.staticfiles' And use my own server of static files through urlpattern description And have settings. DEBUG = True

+6
source share
2 answers

I found that by default django is 'runningerver', preempts / static / urls: even using special middleware, you cannot force django to point '/ static /' to your code.

The only solution found: use the --nostatic option for "./manage.py runningerver", then you can use your own url templates and views to serve static files.

+5
source

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

0
source

Source: https://habr.com/ru/post/916930/


All Articles