logout button
Date: March 23rd 2016
Last updated: March 23rd 2016
I got stumped by this because I didn't know how to use urls to create the logout button.
template with the logout button
<div class="headermenu">
<a href="{% url 'surferprofile:logout' %}"
style="text-decoration: none;">Logout
</a>
</div>
urls.py
When a user clicks on the text "Logout", the call goes to urls.py using the name logout.
from django.conf.urls import url
from . import views
app_name = 'surferprofile'
urlpatterns = [
url(r'^logout/$', views.logout_user, name='logout'),
]
views.py
The logout_user() method simply redirects the user to the splash (welcome/landing) page. Obviously this assumes that there is a splash page to go to.
def logout_user(request):
logout(request)
return HttpResponseRedirect('/splash')