I would like to use some custom CSS and images on my custom 404/500 pages that I made. Django doesn't include the STATIC_URL variable in those pages though. What would be the best way to accomplish this? I also tried making a custom 404/500 view and rendering an arbitrary HTML file but it didn't work out so great.
相关问题
- Django __str__ returned non-string (type NoneType)
- Django & Amazon SES SMTP. Cannot send email
- Django check user group permissions
- Django restrict pages to certain users
- UnicodeEncodeError with attach_file on EmailMessag
相关文章
- Profiling Django with PyCharm
- Why doesn't Django enforce my unique_together
- MultiValueDictKeyError in Django admin
- Django/Heroku: FATAL: too many connections for rol
- Django is sooo slow? errno 32 broken pipe? dcramer
- Django: Replacement for the default ManyToMany Wid
- Upgrading transaction.commit_manually() to Django
- UnicodeEncodeError when saving ImageField containi
I believe you're just going to have to override the default 404/500 error handling. This should get you started:
http://docs.djangoproject.com/en/dev/topics/http/views/#customizing-error-views
Here's how I would do it:
It's worth mentioning the reason Django doesn't do this by default:
I run into the same problem and found a solution which doesn't need custom templates or handlers. From Django 1.4 on you can use the tags get_media_prefix and get_static_prefix to access MEDIA_URL and STATIC_URL when they are not in the context.
In my particular case (Django 1.5), I wanted to access some static images in my page 500.html. I just added at the beginning of the template
and then obtained the media and static urls with these tags
You can find the official documentation here: https://docs.djangoproject.com/en/1.5/ref/templates/builtins/#get-static-prefix