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

  • Home
  • SEARCH
  • 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 481293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:58:47+00:00 2026-05-13T00:58:47+00:00

I learned how to authenticate users in Django months ago, but I’ve since upgraded

  • 0

I learned how to authenticate users in Django months ago, but I’ve since upgraded and am having some problems so it occurred to me this morning that I may not have been doing it correctly from the start so I decided to ask.

In my project’s urls.py file I’ve got ^accounts/login/$ and ^accounts/logout/$ both wired up to the built-in login() and logout() views (at django.contrib.auth.views) and ^accounts/profile/$ is connected to a view I’ve written, called “start_here” whose contents are basically this:

def start_here(request):
    if request.user:
        user_obj = request.user
    else:
        user_obj = None
    is_auth = False
    if request.user.is_authenticated():
        is_auth = True
    return render_to_response("profile.html", {'auth': is_auth,'user': user_obj,})

Now, “profile.html” extends a master template, called master.html, inside which is a “navbar” block whose contents are supposed to change if ‘auth’ == True (snippet below)

{% block navbar %}
            {% if auth %}
                <a href="">Link A</a>
                <a href="">Link B</a>
                <a href="">Link C</a>
                <a href="">Link D</a>
                <a href="">Link E</a>
                <a href="">Link F</a>
                <a href="/accounts/logout/">Logout</a>
            {% else %}
                <a href="/accounts/login/">Login</a>
            {% endif %}
{% endblock %}

My problem is that when I log in, and it redirects to /accounts/profile, the navbar doesn’t display Links A-F + Logout, it displays only “login”. It doesn’t work the way I expect it to unless I manually copy-paste the above block into profile.html. When calling render_to_response(), does the context I provide get passed to the parent template as well as the child?

Full source to master and profile.html: http://dpaste.com/hold/128784/
I don’t see anything suspect in the code.

  • 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-13T00:58:47+00:00Added an answer on May 13, 2026 at 12:58 am

    This answer is tangential, but Jim’s suggestion to use RequestContext is so good I want to explicitly explain how to do it.

    You can reduce your start_here function to

    from django.template import RequestContext
    
    def start_here(request):
        return render_to_response("profile.html", {},
            context_instance=RequestContext(request))
    

    By using RequestContext, user is automatically added to the context. Instead of using

    {% if auth %}
    

    use

    {% if user.is_authenticated %}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I learned java generics some time ago, but now I'm learning collections and found
I learned HTML and CSS about 8 months ago, and recently, about 2 months
I learned that it's recommended to use BigDecimal instead of Float , but this
Learned all about computing algorithm costs in College, but that was so long ago
I learned some time ago about Decision Trees and Decision tables. I feel that
I learned about $_SESSION about several weeks ago when creating a login page. I
I learned the object-oriented in Java. Now in develop in C#. This means that
I learned an example of usage of sockets. In this example a client sends
I learned something about DLL's yesterday. But I haven't found the way how to
i learned earlier how to move between two forms back and forth. but what

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.