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 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 some time ago about Decision Trees and Decision tables. I feel that
Learned all about computing algorithm costs in College, but that was so long ago
I learned about this: desc survey.bb_data through SO, but this only tells you what
I learned a lot of Perl RegEx syntax rules, but probably the only way
I learned that a signal is not changed immediately when encountering an expression, but
I learned today that NetBeans 6.5 should have an on-the-fly compilation of (single) Java
I learned Java in college, and then I was hired by a C# shop
EDIT: Learned that Webmethods actually uses NLST, not LIST, if that matters Our business
I learned to use "exists" instead of "in". BAD select * from table where
I learned C++ when it was C with classes. I find myself increasingly disliking

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.