Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.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重定向_Django_Authentication_Redirect_View - Fatal编程技术网

针对特定用户的Django重定向

针对特定用户的Django重定向,django,authentication,redirect,view,Django,Authentication,Redirect,View,我们是否可以重定向到使用django.contrib.auth.models登录的特定用户的特定应用程序视图 重定向不起作用 对于特定用户,可以将其重定向到特定的应用程序主页,如果可以,如何重定向?在视图中: redirect_user = User.objects.get(id=1) (something to identify a user) if request.user == redirect_user: return(whatever you want to redirect

我们是否可以重定向到使用django.contrib.auth.models登录的特定用户的特定应用程序视图

重定向不起作用 对于特定用户,可以将其重定向到特定的应用程序主页,如果可以,如何重定向?

在视图中:

redirect_user = User.objects.get(id=1) (something to identify a user)
if request.user == redirect_user:
    return(whatever you want to redirect to)
else:
    return(where everyone gets directed to)

如果您想在每个视图上都使用此功能,可以考虑制作自定义装饰器。

谢谢您的回答。它解决了这个问题。谢谢