Please not here django cannot find the exception parameter
In previous community questions i could not find any question that points to the exception parameter not found issue. Please note that i am not using django templates {% %} in my 404.html file
I think when django does not find the exception parameter it returns server error 500.
I think this is an issue with finding the template. Is errors a directory within your project base dir templates? (In other words project_dir/templates/errors/404.html)
So - what this is telling us is that exception is not a positional parameter - it’s a keyword parameter.
You could try: def custom_page_not_found(request, exception=None, template_name="errors/404.html"):
or leave it at: def custom_page_not_found(request, **kwargs):
and get the keyword args from kwargs as needed. (e.g. kwargs.get('template_name', 'errors/404.html')
It’s working now even the data from the templates tags is coming through.
I am a beginner and it’s been a year since I started learning Django. Can you tell me what was going wrong? or reference an article/blog for that matter?
Actually I can’t - this surprised me as well. When I started looking at this, I more-or-less stumbled across this solution and I can’t say I know why it’s behaving like this.
I see that Django 3.2.9 added Python 3.10 compatibility - if you’re really curious about it, you could either try updating to the latest 3.2 branch or going back to a Python 3.9 instance just to see if there are some version-related issues involved.
(I don’t see anything in any of the newer Django 3.2.x release notes identifying a bug in that area. so that’s probably not the issue there - but I’d try updating anyway just to see.)