2

I have custom 404 and 500 error handlers setup in django and they work in development, but with Apache they just show the default apache Internal Server Error page, even for 404 errors.

Here is my urls.py:

handler400 = 'views.error400'
handler403 = 'views.error403'
handler404 = 'views.error404'
handler500 = 'views.error500'

I've read of many ways to set up custom error pages in apache, but all of the approaches I tried with django did not work. What is the correct way to set this up for Apache/mod_wsgi and Django?

Do I remove those lines from my urls.py and add some lines to my apache.conf?

What lines should be added to apache.conf as I'm not sure how to access views from the apache configuration file and the normal urls.py routing for Django is not working for the custom error pages since as I suspect Apache is intercepting the requests and providing it's own pages.

I just want to use my templates for my custom error pages (which include inheriting from a base template).

How can I achieve this, I can't find a decent answer anywhere?

Thanks

EDIT:

I tried editting the Apache config to add ErrorDocument 500 /templates/500.html and such but it did not work.

I currently have the error page in my templates directory, they each inherit from a base template. Also, they each have their own view to handle the responses.

But no matter what I do, removing those lines from urls.py, adding stuff to apache config, etc. I can't get anything but the typical Internal Server Error apache page to display on any error, even one's that aren't 500 errors.

What can I do to get this working? Worked fine on the django development server, but as soon as apache was thrown into the mix I can't get it to work using either apache or django, I must be missing something but what?

1 Answer 1

2

You can remove those lines from urls.py. Django will look up to your templates to get those.

Just put 404.html and 500.html files into your_app/templates/ directory.

Sign up to request clarification or add additional context in comments.

10 Comments

I have those files in my templates directory. If I remove those lines from my urls.py, what do I add to my Apache config to make them work?
So add something like ErrorDocument 404 /templates/404.html? And the same for 500.html and even 403.html
Django router will take care of that, you don't have to change Apache config.
But if I removed those lines from urls.py how will Django router take care of it ? I just gave it a try and still get the default Apache pages. I'm a bit confused here about how Django could handle it when I just removed those lines from urls.py. It seems that Apache needs to handle it as it is giving me it's default error pages. Am I missing something here?
Do you have TEMPLATE_DIRS setting set? You should have those templates in that directory.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.