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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T03:22:10+00:00 2026-06-19T03:22:10+00:00

I am stuck in this small issue. I have a page where the user

  • 0

I am stuck in this small issue. I have a page where the user needs to log in. after login everything is fine. but once the user is logged in, if he hits the address bar with enter, this error – Key 'username' not found in <QueryDict: {}> is coming and showing error on the page.
this is my code for logging in:

if request.path == '/cms/':
    request.session['username'] = request.POST['username']
    request.session['password'] = request.POST['password']
    #check for login
    if User.objects.exists():
        u=User.objects.get(id=1)
        if u.username==request.session['username'] and u.password==request.session['password']:
            #do some stuff here, cos i am logged in

now, if i reload the page, it is fine, but with enter not. should i save the POST data into session? what is happenning here actually?

thanks a lot

  • 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-19T03:22:12+00:00Added an answer on June 19, 2026 at 3:22 am

    What does request.POST contain? It does not contain the username. To find out what it contains you can print request.POST which should show up on your dev server, or you can log the value somewhere or you can enter debugger and inspect using import pdb; pdb.set_trace()

    python dictionaries have get method for this case

    request.POST.get('username')

    If the key is not found it returns None by default instead of a KeyError

    are you making a post request to your view?

    <form method="post" action="/yoururlhere/">
      <input type="text" name="username" />
      <input type="text" name="password" />
      <input type="submit" value="submit" />
    </form>
    

    The above form would post the username and password fields. I think it is truley important to read https://docs.djangoproject.com/en/dev/topics/auth/ in its entirety, and learn how to use django built in user management. Django provides User objects (which it looks like you are using) and provides all the necessary functions to manage their authentication.

    It is important because:

    1. It is easier than doing it manually, once you learn it
    2. Because it is easier it is most likely going to be faster than manageing authentication yourself
    3. It is less prone to error than doing it manually. DJango source code has lots of eyes looking at it and lots of tests covering it. Please use the built in tools for the safety of your site.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am stuck at a small problem. I have this button within a form
i have a small issue im creating multi table and im stuck, i want
I have been stuck with this issue now all morning. I actually saw this
Im stuck with this little project in C# but basically my problem is this:
I have been stuck on this for a while now and I cannot seem
I am stuck with this issue for a long time. I searched for this
I've got an small issue, I'm trying to make my own forum, but I
I'm new to the facebook api, and i have a small issue. I'm trying
I've already asked similar question on this issue on stack overflow already, but I
I have a small (or perhaps not so small) issue with some ASP.NET/Castle Monorail

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.