For example I can point the url '^/accounts/password/reset/$'
to django.contrib.auth.views.password_reset
with my template filename in the context but I think need to send more context details.
I need to know exactly what context to add for each of the password reset and change views.
You just need to wrap the existing functions and pass in the template you want. For example:
To see this just have a look at the function declartion of the built in views:
http://code.djangoproject.com/browser/django/trunk/django/contrib/auth/views.py#L74
Another, perhaps simpler, solution is to add your override template directory to the DIRS entry of the TEMPLATES setting in settings.py. (I think this setting is new in Django 1.8. It may have been called TEMPLATE_DIRS in previous Django versions.)
Like so:
Then put your override template files under
my_app/templates
. So the overridden password reset template would bemy_app/templates/registration/password_reset_form.html
The documentation says that there only one context variable,
form
.If you're having trouble with login (which is common), the documentation says there are three context variables:
form
: A Form object representing the login form. See the forms documentation for more on Form objects.next
: The URL to redirect to after successful login. This may contain a query string, too.site_name
: The name of the current Site, according to the SITE_ID setting.I was using this two lines in the url and the template from the admin what i was changing to my need
If you take a look at the sources for django.contrib.auth.views.password_reset you'll see that it uses
RequestContext
. The upshot is, you can use Context Processors to modify the context which may allow you to inject the information that you need.The b-list has a good introduction to context processors.
Edit (I seem to have been confused about what the actual question was):
You'll notice that
password_reset
takes a named parameter calledtemplate_name
:Check password_reset for more information.
... thus, with a urls.py like:
django.contrib.auth.views.password_reset
will be called for URLs matching'/accounts/password/reset'
with the keyword argumenttemplate_name = 'my_templates/password_reset.html'
.Otherwise, you don't need to provide any context as the
password_reset
view takes care of itself. If you want to see what context you have available, you can trigger aTemplateSyntax
error and look through the stack trace find the frame with a local variable namedcontext
. If you want to modify the context then what I said above about context processors is probably the way to go.In summary: what do you need to do to use your own template? Provide a
template_name
keyword argument to the view when it is called. You can supply keyword arguments to views by including a dictionary as the third member of a URL pattern tuple.You can do the following:
Explanation:
When the templates are loaded, they are searched in your INSTALLED_APPS variable in settings.py . The order is dictated by the definition's rank in INSTALLED_APPS, so since your app come before 'django.contrib.auth' your template were loaded (reference: https://docs.djangoproject.com/en/dev/ref/templates/api/#django.template.loaders.app_directories.Loader).
Motivation of approach: