[Answered ]-How to redirect to another page

1๐Ÿ‘

โœ…

You can use the redirect shortcut function:

from django.shortcuts import redirect
return redirect('some-view-name')

You can also specify a URL apart from a named view. So if your index url does not have a name, you can specify โ€˜/โ€™.

This shortcut function is essentially the same as:

from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
return HttpResponseRedirect(reverse('some-view-name'))

In order to have a named view, in your urls.py you have to provide a name argument. For instance:

urlpatterns = [
    url(r'^$', views.index, name='index'),
    url(r'^some-view$', views.something, name='some-view-name'),
]

More on that on Django tutorial, Django URL dispatcher.

๐Ÿ‘คWtower

1๐Ÿ‘

You can use redirect

if sessionCheck(request):
    redirect(your_url)
else: 
    ...
๐Ÿ‘คGiuseppe Pes

Leave a comment