Reputation: 2084
I have a model user2 with a one to one field with the user model, user2 has an additional field user_type where it could be "etud", "ensg" "chef" or "tech". what I would like to do is to serve each type of users a different version of the site, currently what I'm doing is that I have everything on one page, then I check the user type for some specific HTML tags, and I'm doing this for all the site pages. so, how would I do something like that ? and is the method i'm using the best way ?
Upvotes: 0
Views: 280
Reputation: 811
There are multiple ways to do.
Rendering pages on users type based
Let's say they land on a URL /home/, and you can map that different home page, After home_view() called.
Here you have to create generic base_home.html from this template you have to extends user_type specific template with the diff theme.
def home_view(request):
context = {} # add your template context here common for all user.
if request.user.user_type == "etud":
# update your user_type specific context here.
template_name = etud_home.html
response = TemplateResponse(request, template_name, context)
return response
if request.user.user_type == "ensg":
template_name = ensg_home.html
response = TemplateResponse(request, template_name, context)
return response
If you want to go with a more generic way check process_template_response middleware
Upvotes: 2