Using Django views I want to redirect a user based on their permission levels.
I have a template view that works.
class theTableView(generic.TemplateView):
template_name = 'adminTable.html'
What I am trying to do looks something like this:
class TheTableView(generic.TemplateView):
if self.request.user.is_superuser==True:
tempTemplate = 'goodAdminTable.html'
elseif self.request.user.is_authenticated==True:
tempTemplate = 'goodUserTable.html'
template_name = tempTemplate
I was able to do this in the rest_framework api return for the data.
I need to be able to check the user permissions and redirect them to the appropriate template_name based on the results.
Any help is appreciated. Thanks.
You can do this by overriding get_template_names() method like this
class theTableView(generic.TemplateView):
template_name = 'adminTable.html'
def get_template_names(self):
if self.request.user.is_superuser:
template_name = 'goodAdminTable.html'
elif self.request.user.is_authenticated:
template_name = 'goodUserTable'
else:
template_name = self.template_name
return [template_name]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With