




This article describes how to override a view from an external Django app which is a FAQ on StackOverflow and IRC.
You should understand that your urls.py is a really central and critical part of your django project.
You are not supposed to edit the code from an external app. Unless you fork it first on github.
If you want to override templates/userena/activate_fail.html, then all you have to do is create your own templates/userena
directory and make your own activate_fail.html
in it.
Probably the first thing you should check in an external app is its urls.py. Views that are properly coded should support plenty of arguments. For example, userena has a signup view with such a signature (at the time of writing):
This means that you can replace the form used by the signup view. To do so, open your urls.py
, add what we are going to need at the top:
Then, find the include the external app’s urls, something like:
Before that, add your url override:
Now, your custom url definition will be the first to be hit when a visitor hits /userena/signup/. Which means that /userena/signup/
will use YourSignupForm
instead of userena’s signup form.
This trick works with any view argument. The ones you should see the most often are:
template_name
: lets you change the template nameextra_context
: lets you add a dict that will be added to the contextAlmost every view should have these arguments.
Overriding a view requires to override the url of the view you want to replace. If you want your own signup view to be used, then just override the url:
Decorating a view is like overriding a view, but reuses the external app’s view. Basically, it’s the same than overriding a view (see above), but your view will look like this
If you are not familiar with pip and virtualenv first, please read the post about using pip and virtualenv first.
For example:
pip install django-userena
pip uninstall django-userena
pip install -e git+git@github.com:your-username/django-userena.git#egg=django-userena
yourenv/src/django-userena
lauxley from #django@irc.freenode.net proofreaded this article.
Thanks !