» Customize Django class base view at global (project wide)
Customize Django class base view at global (project wide)
|September 15, 2014
Posted by forumadmin
I am developer a Django website which will do SSO for most of the web pages, and I was using Class based views extensively, the official documentation said that we can decorate class based view in this way:
from django.contrib.auth.decorators import login_required
from django.utils.decorators import method_decorator
from django.views.generic import TemplateView
template_name = 'secret.html'
def dispatch(self, *args, **kwargs):
return super(ProtectedView, self).dispatch(*args, **kwargs)
I’ve implemented a customized
sso_login_required decorator, but since most of my pages will do SSO, I believe doing above for most of my views is absolutely not the right way, I was thinking doing that at a global level, I guess I have two options to implement/override the dispatch method above:
- Create my
BaseView class which inherits from
django.views.generic.base.View, and let all my views inherits from this customized BaseView.
dispatch method of
django.views.generic.base.View at my project level
What is the best practice here according to my requirement (SSO for most pages)? Any recommendation or suggestions are highly appreciated!
More Related Questions
- Which CAS implementation to use in django? Which CAS implementation should i use to enable CAS single sign on to my django app (trusing a specified CAS server, I'm not interested in creating a CAS provider) ? What I can find are […]
- Write a SSO application on GAE I'm looking for a solution to implement a SSO (single-sign on) application, and this app need to be in python and run on GAE (Google App Engine). This applications needs to be implemented […]
- Django Manager Chaining I was wondering if it was possible (and, if so, how) to chain together multiple managers to produce a query set that is affected by both of the individual managers. I'll explain the […]
- How do I filter ForeignKey choices in a Django ModelForm? Say I have the following in my models.py:
name = ...
company = models.ForeignKey(Company)
name = ...
- Django: how do you serve media / stylesheets and link to them within templates Variations of this question have been asked, but I'm still unable to get my styleheets to load correctly when my templates are rendered.
I'm attempting to serve static media from the […]
- Django Passing Custom Form Parameters to Formset I have a Django Form that looks like this:
option = forms.ModelChoiceField(queryset=ServiceOption.objects.none())
rate = […]
- Django filtering different parents in template I considered a evaluation Model in my project, which is like
question = models.ForeignKey(Question)
value = […]
- Paginated based on the alphabet (A-Z) I have a simple contacts application where I want to paginate the contact list based on first name alphabet.
Here is my views.py
contact_list = […]
- Django and mod_wsgi Root URL Config I'm having a very strange issue with serving a Django project using Apache and mod_wsgi. When the URL is requested it seems that mod_wsgi and Django completely ignores my ROOT_URLCONF […]
- Django Foreign key queries In the following model:
title = models.CharField(max_length = 255)
created_by = models.CharField(max_length = 255)