Note that there are some explanatory texts on larger screens.

plurals
  1. POUser authentication in Django
    primarykey
    data
    text
    <p>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.</p> <p>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:</p> <pre><code>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,}) </code></pre> <p>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)</p> <pre><code>{% block navbar %} {% if auth %} &lt;a href=""&gt;Link A&lt;/a&gt; &lt;a href=""&gt;Link B&lt;/a&gt; &lt;a href=""&gt;Link C&lt;/a&gt; &lt;a href=""&gt;Link D&lt;/a&gt; &lt;a href=""&gt;Link E&lt;/a&gt; &lt;a href=""&gt;Link F&lt;/a&gt; &lt;a href="/accounts/logout/"&gt;Logout&lt;/a&gt; {% else %} &lt;a href="/accounts/login/"&gt;Login&lt;/a&gt; {% endif %} {% endblock %} </code></pre> <p>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? </p> <p>Full source to master and profile.html: <a href="http://dpaste.com/hold/128784/" rel="nofollow noreferrer">http://dpaste.com/hold/128784/</a> I don't see anything suspect in the code.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload