Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding extra_context in Django logout built-in view

In django/contrib/auth/views.py there is the definition of the logout view :

def logout(request, next_page=None,
       template_name='registration/logged_out.html',
       redirect_field_name=REDIRECT_FIELD_NAME,
       current_app=None, extra_context=None):

I would like to add extra_context to get rid of the 'Logged out' title that appear when I log off

so I'm trying this in my url confs :

(r'^accounts/logout/$', logout(extra_context={'title':'something else'}) ),

but then I get this error : logout() takes at least 1 non-keyword argument (0 given) what I'm doing wrong? ps: when I do

(r'^accounts/logout/$', logout ),

it works, but then I get the 'Logged out' text...

Thanks, Fred

like image 596
Speccy Avatar asked Jul 20 '11 04:07

Speccy


1 Answers

When you write logout(extra_context={'title':'something else'}), you're actually calling logout right there in the URLconf, which won't work. Any URLconf tuple can have an optional third element, which should be a dictionary of extra keyword arguments to pass to the view function.

(r'^accounts/logout/$', logout, {'extra_context':{'title':'something else'}}),

Alternatively, you could write your own view which calls logout passing in whatever arguments you want -- that's typically how you would "extend" function-based generic views in more complicated cases.

like image 96
Ismail Badawi Avatar answered Sep 20 '22 09:09

Ismail Badawi