0

I am trying to make a web application and I want a log out option in one of my template which will redirect to my home page. How should I do it?

I have a home page name 'home.html' which have a google sign in option by social o-authentication process and once signed in it will redirect it to another template named 'jumbotron.html'. But if I refresh and try logging it again it directly takes me to that template.

So I basically want a log out option on a template 'jumbotron.html' which will redirect me to the home page and have to log in again. How should I do it? Thank you in advance!

Seba Cherian
  • 1,755
  • 6
  • 18
Aman Agrawal
  • 11
  • 1
  • 5
  • 4
    Possible duplicate of: https://stackoverflow.com/questions/5315100/how-to-configure-where-to-redirect-after-a-log-out-in-django – Walucas Mar 27 '19 at 12:36
  • 5
    Possible duplicate of [How to configure where to redirect after a log out in Django?](https://stackoverflow.com/questions/5315100/how-to-configure-where-to-redirect-after-a-log-out-in-django) – Eel Lee Mar 27 '19 at 14:30

2 Answers2

1

I am assuming index is name of your homepage url

You can specify your logout redirect url in passing next_page in urls.py like this

(r'^logout/$',
    'django.contrib.auth.views.logout', {'next_page': 'index'}
),

you can also set LOGOUT_REDIRECT_URL in settings.py

like

LOGOUT_REDIRECT_URL= 'index'
Yugandhar Chaudhari
  • 3,831
  • 3
  • 24
  • 40
0

Lets assume home as your homepage url.

In your urls.py:

from django.contrib.auth import views as auth_views

url(r"^logout/$", auth_views.LogoutView.as_view(), name="logout"),

In your settings:

LOGOUT_REDIRECT_URL= 'home'

In your template:

<a href="{% url 'logout' %}" class="btn btn-default btn-flat">Sign out</a>

If the logout url is inside any django app then:

<a href="{% url 'appname:logout' %}" class="btn btn-default btn-flat">Sign out</a>
Niladry Kar
  • 1,163
  • 4
  • 20
  • 50