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 8746869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:15:46+00:00 2026-06-13T12:15:46+00:00

I am just trying to run a simple {% if user.is_authenticated %} . But

  • 0

I am just trying to run a simple {% if user.is_authenticated %} . But it always return False.

Here are my all the files.

views.py

from django.shortcuts import render_to_response, redirect
from django.core.urlresolvers import reverse
from django.template import RequestContext
from django.contrib.auth.models import User
from django.http import HttpResponse
from django.contrib.auth.hashers import *
from forms import UserLoginForm
from models import UserLogin

def index(request):
    return render_to_response('index.html', context_instance = RequestContext(request))

def login(request):
    if request.method == 'POST':
        form = UserLoginForm(request.POST or None)
        if form.is_valid():
            email_from_form = form.cleaned_data['email']
            password_from_form = form.cleaned_data['password']
            users = User.objects.filter(email = email_from_form)

            for j in users:
                if j.email == email_from_form:
                    pass_match = check_password(password_from_form, j.password)
                    if pass_match:
                        return redirect(reverse('profile'), context_instance = RequestContext(request))
                    else:
                        return HttpResponse('Entered password did not match')
                else:
                    return HttpResponse('Entered email does not exist')
        else:
            return HttpResponse(form.errors)
    else:
        form = UserLoginForm()

    return render_to_response('login.html', {'form':form}, context_instance = RequestContext(request))


def profile(request):

    return render_to_response('profile.html', context_instance = RequestContext(request))

forms.py

from django import forms

class UserLoginForm(forms.Form):
    email = forms.EmailField(max_length = 100)
    password = forms.CharField(max_length = 100)

models.py

from django.db import models

class UserLogin(models.Model):
    email = models.EmailField(max_length = 100)
    password = models.CharField(max_length = 100)

    def __unicode__(self):
        return self.email

profile.html

<html>
<head>
    <title>profile</title>
</head>
<body>
    {% if user.is_authenticated %}
        Welcome user, you are loged in..
    {% else %}
        You are not logged in
    {% endif %}
</body>
</html>

login.html

<html>
<head>
    <title>login</title>
</head>
<body>
    <form action="{% url login %}" method="POST">
        {% csrf_token %}
        {{ form.as_p }}
        <input type="submit" id="submit" name="submit" value="Login" />
    </form>

</body>
</html>

It always returning You are not logged in

I am new to django and I dont understand this why it is like this.

  • 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-13T12:15:47+00:00Added an answer on June 13, 2026 at 12:15 pm

    You never log your user in. Try something along the following lines:

    from django.contrib.auth import authenticate, login as auth_login
    
    if request.method == 'POST':
        form = UserLoginForm(request.POST or None)
        if form.is_valid():
            username = User.objects.get(email=form.cleaned_data['email'])
            password = form.cleaned_data['password']
            user = authenticate(username=username, password=password)
            if user:
                if user.is_active:
                    auth_login(request, user)
                    return HttpResponseRedirect(request.GET.get('next',
                                                settings.LOGIN_REDIRECT_URL))
            else:
                error = 'Invalid username or password.'
    

    Updated to use your form for clarity; error checking excluded.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been trying to Run a simple program on NetBeans but just after I
I was just trying to run the ScanTest from ZXing on Xcode just to
I am a fairly experienced OpenMP user, but I have just run into a
I am trying to run a simple FQL query: SELECT aid,name FROM album WHERE
I've got a simple question that I just KNOW won't be possible, but here
I'm trying to run a query on a very simple table but I'm not
I am trying just to run a servlet on my local Tomcat with Eclipse.
I'm trying to run just one migration out of a whole bunch in my
I'm trying to make a RLE (Run-Length Encoder) Programme just for characters. I read
just trying to test for equality in this piece of code, but getting a

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.