Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Assuming your <code>urls.py</code> looks similar to this:</p> <pre><code>from django.conf.urls.defaults import * from django.views.generic.simple import direct_to_template urlpatterns = patterns('', url(r'^$', 'mywebsite.index', name='index'), url(r'^login/$', 'django.contrib.auth.views.login', name='login'), url(r'^logout/$', 'django.contrib.auth.views.logout_then_login', name='logout') ) </code></pre> <p>Then in your settings file, put something like this:</p> <pre><code>LOGIN_REDIRECT_URL = 'index' LOGIN_URL = 'login' LOGOUT_URL = 'logout' </code></pre> <p>Which will cause the login page to redirect to the <code>mywebsite.index</code> view (since the <code>name='index'</code> matches this view, and that's what we set in <code>LOGIN_REDIRECT_URL</code>.)</p> <blockquote> <p>I know they gave an example of a template but I want an example of how to create the actual view and use it.</p> </blockquote> <p>The "actual view" is provided by django at <code>django.contrib.auth.views.login</code>, so you don't need to create the view at all. That's the whole point of the section you're reading. You provide the template, that template posts to the view, and then the view redirects to <code>LOGIN_REDIRECT_URL</code>.</p> <p>Now when you use the <a href="https://docs.djangoproject.com/en/dev/topics/auth/default/#django.contrib.auth.decorators.login_required" rel="nofollow">@login_required</a> decorator, django will redirect the users to your login template via the built in django login view.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload