[Answered ]-Django: 1 view for different users?

1đź‘Ť

Check this answer for discussion on user.is_authenticated. You can also check within the view to see who the user is (see here) and modify the context being sent to the template accordingly. Another option would be to modify your view to simply show different types of users different templates.

Lots of ways to accomplish this, not sure if there’s a “correct” one.


Your comment made me realize that this is exactly what the Groups feature of the auth package is for. You can assign users to groups, query whether they’re a member of the group, and then show content based on that. I apologize that I don’t have time to write out sample code, but there’s tons of stuff here on SO about it; hopefully that’s a good starting point for you.

👤eykanal

1đź‘Ť

I don’t know if it is good style. But you could use

{% include user_type_sidemenu_template with arg1=... %}

in your template and provide different templates for the sidemenu for each user_type. You can then set the template variable user_type_sidemenu_template to the corresponding template name in your view.

👤Denis

Leave a comment