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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T03:36:19+00:00 2026-05-19T03:36:19+00:00

I use the backend solution from django. I just want to get a username

  • 0

I use the backend solution from django. I just want to get a username from the cookie or the session_key to get to know the user. How I can do it?

from django.contrib.auth.models import User
from django.contrib.sessions.models import Session

def start(request, template_name="registration/my_account.html"):
    user_id = request.session.get('session_key')
    if user_id:
        name = request.user.username
        return render_to_response(template_name, locals())
    else:
        return render_to_response('account/noauth.html')

Only else is coming up. What am I doing wrong?

Am I right then that authenticated means he is logged in?

–> Okay this I got!
Firstly, if you have some clarification to a question, update the question, don’t post an answer or (even worse) another question, as you have done. Secondly, if the user is logged out, by definition he doesn’t have a username.

I mean the advantage of Cookies is to identify a user again. I just want to place his name on the webpage. Even if he is logged out. Or isnt’t it possible?

  • 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-05-19T03:36:20+00:00Added an answer on May 19, 2026 at 3:36 am

    piquadrat has absolutely the right answer, but if for some reason you do need to get the user from the session, you call get_decoded() on the session object:

    session_data = request.session.get_decoded()
    user_id = session_data['_auth_user_id']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Guys i would like to use Django as my backend framework and qooxdoo as
I'm trying to use django, and mongoengine to provide the storage backend only with
I want to build a backend application to push messages from server to android
Update: I don't use TFS anymore. But from the comments I can see that
I would like to use D3.js (or maybe Raphaël ) for backend-generated reports using
I use Silex Frame Work and I am trying to delete files in backend
I use subversion to manage my yii website (php framework) and have separate backend
I use an Access database used just as back end. I use some Memo
I am currently using various back-end services and I want to use PHP to
I have a django project that uses a sqlite database that can be written

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.