I want to redirect users to the login page if they enter an invalid url, but I can only figure out how to render the login page without actually changing the url. Is it possible to redirect with handler404 in django? I have the handler404 in my root URLconf and debug mode set to False. Any help is greatly appreciated.
            Asked
            
        
        
            Active
            
        
            Viewed 1,919 times
        
    1 Answers
3
            You can try this Django, creating a custom 500/404 error page
and Designing Custom 404 And 500 Error Pages In Django
to redirect your custom url override described method in this link
def handler404(request, *args, **argv):
    return redirect('home')
 
    
    
        shafik
        
- 6,098
- 5
- 32
- 50
- 
                    Thank you for your response. I am interested in redirecting to a home page as opposed to creating a custom error page, but I am not sure if this is possible? – dakota Dec 23 '18 at 07:12
- 
                    I'm sorry, I'm very new to django. So i have my URLconf as handler404 = 'app.views.handler404' and my view as def handler404(request): return redirect('home'). Is this correct? – dakota Dec 23 '18 at 07:39
- 
                    test it. If throw problem, comment the error traceback – shafik Dec 23 '18 at 07:41
- 
                    It's giving me Server Error(500) – dakota Dec 23 '18 at 07:50
- 
                    How do I get a more detailed traceback? – dakota Dec 23 '18 at 08:06
- 
                    Perfect! I got it to work, I just needed to add an exception argument to the handler404 view and change my home/ url path to a re_path so that it wouldn't get stuck in a redirect loop. Thank you for your help! – dakota Dec 23 '18 at 08:24
