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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:35:32+00:00 2026-06-11T08:35:32+00:00

when i try to login it shows : KeyError at /admin/ ‘loggedin’ it shows

  • 0

when i try to login it shows :

KeyError at /admin/

'loggedin'

it shows this error only when i submit with correct username and pwd. so i think it is about my admin view..

here is my log in view :

def log_user_in(request):
    if request.method=='POST':
        uname = request.POST['username']
        password = request.POST['password']
        user = authenticate(username=uname, password=password)
        form = LoginForm(request.POST)
        if form.is_valid():
            if user is not None:
                request.session['loggedin']="djangoo"
                login(request, user)
                return HttpResponseRedirect('/admin/')
    else:
        form = LoginForm()

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

and log out view :

def log_user_out(request):
    user = request.user
    try:
        del request.session['loggedin']
    except KeyError:
        pass
    logout(request)
    return HttpResponseRedirect('/blog/%s/'%(user))

and admin view :

def admin_view(request):

    if request.session['loggedin'] == "djangoo":
    #other codes..

here is my urls.py:

urlpatterns = patterns('blog.views',
    url(r'^superadmin/', include(admin.site.urls)),

    url(r'^blog/(?P<username>[-\w]+)/$',view='index', name='index'),
    url(r'^blog/(?P<username>[-\w]+)/post/(?P<postslug>[-\w]+)',view='single_post', name='view_blog_post'),
    url(r'^login/$', view='log_user_in'), # i log in to admin page from this url
    url(r'^admin/$', view='admin_view', name='admin'),# to this url
    url(r'^admin/logout/$', view='log_user_out', name='logout'),
    url(r'^admin/post/add/$', view='add_post',name='addpost'),
    url(r'^admin/post/edit/(?P<post_id>\d+)', view='edit_post', name='editpost'),
    url(r'^admin/post/delete/(?P<post_id>\d+)', view='delete_post', name='deletePost'),

)
  • 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-11T08:35:33+00:00Added an answer on June 11, 2026 at 8:35 am

    When you logged out, you manually delete request.session['loggedin'] key, and when you browse to admin page, request.session['loggedin'] fails because you already delete that key.

    You can control if request.session has loggedin key with:

    `loggedin` in request.session
    

    So, writing your admin view like:

    def admin_view(request):
    
        if `loggedin` in request.session and request.session['loggedin'] == "djangoo":
        #other codes..
    

    Or simply use

    if request.session.get('loggedin') == 'djangoo'
    

    as @Alexander Larikov said

    EDIT: I need to mention that, it is good to check if a key exists in dictionary or dictionary-like structure, especially if you also may delete that key in somewhere else.

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

Sidebar

Related Questions

I cannot login using email in CakePHP 2.1, when i try with username then
i am try to insert user and pass to login table it shows an
When I try to login to our WSS demo site the authentication popup forces
I try to provide a login with the facebook-php-sdk. But, when I click on
When try to access site i created after 3 login attempts it gives unauthorised
I am working in a Login page and teh logic is like -> try
I'm creating a login for a website using PHP but when I try to
I'm try to use drupal open id module. When i used to login using
I've been trying to override the file login.xml but no matter what I try,
I followed this tutorial . But whenever I try to log in with my

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.