Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用自定义django 404错误视图重定向?_Django_Url_Redirect - Fatal编程技术网

如何使用自定义django 404错误视图重定向?

如何使用自定义django 404错误视图重定向?,django,url,redirect,Django,Url,Redirect,如果用户输入了无效的url,我想将他们重定向到登录页面,但我只能知道如何呈现登录页面而不实际更改url。是否可以在django中使用handler404重定向?我将根URLconf中的handler404和调试模式设置为False。非常感谢您的帮助。您可以试试这个 及 若要重定向自定义url,请重写此 谢谢你的回复。我对重定向到主页而不是创建自定义错误页面感兴趣,但我不确定这是否可行?对不起,我对django很陌生。因此,我的URLconf为handler404='app.views.handl

如果用户输入了无效的url,我想将他们重定向到登录页面,但我只能知道如何呈现登录页面而不实际更改url。是否可以在django中使用handler404重定向?我将根URLconf中的handler404和调试模式设置为False。非常感谢您的帮助。

您可以试试这个

若要重定向自定义url,请重写此


谢谢你的回复。我对重定向到主页而不是创建自定义错误页面感兴趣,但我不确定这是否可行?对不起,我对django很陌生。因此,我的URLconf为handler404='app.views.handler404',我的视图为def handler404(请求):return redirect('home')。这是正确的吗?测试一下。如果抛出问题,请评论错误回溯。它给了我服务器错误(500)。如何获得更详细的回溯?
def handler404(request, *args, **argv):
    return redirect('home')