Django Http404 and DEBUG 22 mode

I use the staticfiles application during development, which does not work if DEBUG is not enabled.

From the docs :

Warning This will only work if DEBUG is True.

This is because this opinion is extremely ineffective and probably unsafe. It is intended for local development only and should never be used in production.

Also, when using staticfiles_urlpatterns, your STATIC_URL parameter cannot be empty or the full URL, for example http://static.example.com/ .

I am trying to view my Http404 templates, and of course they do not work in DEBUG mode. So I'm in trick 22 - if I want to view page 404, I need to disable DEBUG, but then no static files are servers, and I don't see any images, etc.

+4
source share
2 answers

You can just pretend you're in production. Run:

 python manage.py collectstatic --noinput 

So that all your files are copied to STATIC_ROOT . Then temporarily add the following to urls.py:

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

You will need to run collectstatic every time you make changes to some static files, so I suggest editing something like Firebug in real time and then saving the finished product. Also, be sure to remove the static directory and remove this line from urls.py when done.

+3
source

I have not tried it myself, but you can try setting DEBUG_PROPAGATE_EXCEPTIONS = True

https://docs.djangoproject.com/en/dev/ref/settings/

-1
source

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


All Articles