Adding extra_context in Django logout built-in view

前端 未结 3 1797
情书的邮戳
情书的邮戳 2020-12-19 05:56

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

def logout(request, next_page=None,
       template_name=\'registration/logged_o         


        
3条回答
  •  庸人自扰
    2020-12-19 06:43

    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.

提交回复
热议问题