简体   繁体   中英

Django passing variables to modules - login() got an unexpected keyword argument

In my Django urls.py, I have a login page:

(r'^accounts/login/$', 'django.contrib.auth.views.login', { 'design_form': True }),

I want to pass a variable 'design_form': True to django.contrib.auth.views.login, so that my accounts/login page displays the way that I want it to. django.contrib.auth.views.login bypasses views.py, so I have no chance of doing

variables = RequestContext(request, {
    'design_form': True,
    })

as I usually would. So how do I pass variables to the module without getting the login() got an unexpected keyword argument error?

There is an extra_context variable you can pass to the login view. Use it like this:

(r'^accounts/login/$', 'django.contrib.auth.views.login', { 'extra_context' : {'design_form': True }}),

That will put design_form in the context for the template.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM