Assaf Lavie
Assaf Lavie

Reputation: 75983

Django Http404 and DEBUG mode catch 22

I'm using the staticfiles app during development, which doesn't work unless DEBUG is turned on.

From the docs:

Warning This will only work if DEBUG is True.

That's because this view is grossly inefficient and probably insecure. This is only intended for local development, and should never be used in production.

Additionally, when using staticfiles_urlpatterns your STATIC_URL setting can't be empty or a full URL, such as http://static.example.com/.

I'm trying to view my Http404 templates, though, and of course they don't work in DEBUG mode. So I'm in a catch 22 - if I want to view the 404 page I have to turn off DEBUG, but then no static files are servers and I can't see any images, etc.

Upvotes: 4

Views: 761

Answers (2)

aglassman
aglassman

Reputation: 2653

I haven't tried it myself, but you might try setting DEBUG_PROPAGATE_EXCEPTIONS = True

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

Upvotes: -1

Chris Pratt
Chris Pratt

Reputation: 239290

You can simply pretend you are in production. Run:

python manage.py collectstatic --noinput

To have all your files 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'll have to run collectstatic each time you make a change to any static files, so I would suggest live-editing in something like Firebug and then saving the finished product. Also, remember to delete the static directory and remove that line from urls.py when you're done.

Upvotes: 3

Related Questions