Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9143743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:06:01+00:00 2026-06-17T10:06:01+00:00

I’m new to Django and trying to build a simple login system for my

  • 0

I’m new to Django and trying to build a simple login system for my webpage using django.contrib.auth.views.login with Django 1.4. I have a base template containing the following login form which is then extended by other template pages on my website:

<form method="post" action="/accounts/login/">
{% csrf_token %}
<p><label for="id_username">Username:</label> <input id="id_username" type="text" name="username" maxlength="30" /></p>
<p><label for="id_password">Password:</label> <input type="password" name="password" id="id_password" /></p>
<input type="submit" value="Log in" />
<input type="hidden" name="next" value="{{ request.get_full_path }}" />
</form>

However when I try to login I get the following message:

“Forbidden (403)
CSRF verification failed. Request aborted. Reason given for failure:
CSRF token missing or incorrect.”

Relevant snippets from urls.py:

url(r'^accounts/login/$', 'django.contrib.auth.views.login')

and settings.py:

TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.request',
)

.....

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
)
.....
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)

Any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T10:06:03+00:00Added an answer on June 17, 2026 at 10:06 am

    simple login/logout system could be find here

    Let me briefly explain how to use standard auth through the user model in Django:

    appname/views.py:

    from django.http import HttpResponse
    from django.contrib.auth import authenticate, login
    from django.contrib.auth.decorators import login_required
    from django.template import Context, loader, RequestContext
    from django.shortcuts import render_to_response
    from django.template import 
    
    @login_required
    def stat_info(request):
    return render_to_response('stat_info.html',
      {'is_auth':request.user.is_authenticated()},
      context_instance=RequestContext(request))
    
    @login_required
    def mainmenu(request):
    return render_to_response('mainmenu.html',{},
      context_instance=RequestContext(request))
    

    urls.py:

    from django.conf.urls import patterns, include, url
    from django.contrib import admin
    admin.autodiscover()
    
    urlpatterns = patterns('',
        url(r'^admin/', include(admin.site.urls)),
        (r'^statinfo/$', 'appname.views.stat_info'),
        (r'^accounts/login/$', 'django.contrib.auth.views.login'),
        (r'^accounts/logout/$', 'django.contrib.auth.views.logout', {'next_page' : '/accounts/login'}),
        (r'^mainmenu/$', 'appname.views.mainmenu')
    )
    

    settings.py:

    ...        
    LOGIN_REDIRECT_URL='/mainmenu/'
    ...
    

    templates/registration/login.html:

    {% extends "base.html" %}
    {% block content %}
        {% if form.errors %}
        <p>Your username and password didn't match. Please try again.</p>
        {% endif %}
        <form method="post" action="{% url django.contrib.auth.views.login %}">
        {% csrf_token %}
        <table>
            <tr>
                <td>{{ form.username.label_tag }}</td>
                <td>{{ form.username }}</td>
            </tr>
            <tr>
                <td>{{ form.password.label_tag }}</td>
                <td>{{ form.password }}</td>
            </tr>
        </table>
        <input type="submit" value="login" />
        <input type="hidden" name="next" value="{{ next }}" />
        </form>
    {% endblock %}
    

    templates/base.html:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <link rel="stylesheet" href="style.css" />
        <title>{% block title %}templates/base.html{% endblock %}</title>
    </head>
    <body>
    <div id="sidebar">
        {% block sidebar %}
        <ul>
            <li><a href="/">Home</a></li>
    
            {% if user.is_authenticated %}
                <li><a href="/accounts/logout">Logout</a></li>
            {% else %}
                <li><a href="/accounts/login">Login</a></li>
            {% endif %}
        </ul>
        {% endblock %}
    </div>
    <div id="content">
        {% block content %}{% endblock %}
    </div>
    </body>
    </html>
    

    templates/mainmenu.html:

    <!DOCTYPE html>
    {% extends "base.html" %}
    <html>
    <head>
        <title>{% block title %}templates/mainmenu.html{% endblock %}</title>
    </head>
    <body>
    
    <div id="content">
        {% block content %}
        Mainmenu
        <a href="/statinfo/">stat info</a>
        {% endblock %}
    
    </div>
    
    </body>
    </html>
    

    templates/stat_info.html:

    <!DOCTYPE html>
    {% extends "base.html" %}
    <html>
    <head>
        <title>{% block title %}templates/mainmenu.html{% endblock %}</title>
    </head>
    <body>
    
    <div id="content">
        {% block content %}
        Mainmenu
        <a href="/statinfo/">stat info</a>
        {% endblock %}
    
    </div>
    
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have just tried to save a simple *.rtf file with some websites and
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
We're building an app, our first using Rails 3, and we're having to build
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have thousands of HTML files to process using Groovy/Java and I need to
I'm making a simple page using Google Maps API 3. My first. One marker
I am trying to loop through a bunch of documents I have to put
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.