且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

两个不同视图的一个 url

更新时间:2023-10-26 11:44:28

不,您不能对同一个 URL 有两个不同的视图.Django根据URL和定义的路由决定使用哪个视图函数.

No, you cannot have two different views for the same URL. Django decides which view function to use according to the URL and the routes defined.

在独特的视图中使用自定义代码根据用户类型呈现不同的模板:

Use custom code inside an unique view to render a different template depending on the type of user:

def home(request):
    if user.typeUser == "HA":
        render(request, 'template_a.html')
    else:
        render(request, 'template_b.html')