0
votes

I'm using python social auth in Django to allow for gmail users of a specific url name to log in to a webpage. I have a base.html page with a nav bar that has:

#base.html
<div id="navbar">
<ul>
    <li>
        <img src="{% static "images/thumbnail.jpg" %}" alt='' style="width:48px;height:48px"/>
    </li>
    <li>
        Navbar would go here!
    </li>
    {% if user.is_authenticated %}
    <li>
        Hello, {{ user.get_full_name|default:user.username }}!
    </li>
    <li>
        <a href="{% url 'auth:logout' %}?next={{ request.path }}">Logout</a>
    </li>
    {% else %}
    <li>
        <a href="{% url 'social:begin' 'google-oauth2' %}?next={{ request.path }}">Login</a>
    </li>
    {% endif %}
</ul>

After a user logs in, they are redirected to a homepage, where this navbar shows the correct content. However, when I navigate to another page (with another template) that extends the base.html template, the navbar does not return the username/ and logout links, and instead only shows the login link. When I click the login link, and re-select the same email, it forwards on to /logged-in/ as expected. What is the correct template tag to use to verify a user is logged in?

1
That's a correct check. Are you sure the user is still logged in when you visit the next page? - rbonick
I placed a @login_required decorator above the view, and it renders the page after logging in. Also fails to render the page after logging and opening the url. So, I'm fairly confident the user remains logged in. - DataSwede

1 Answers

1
votes

The second view probably isn't using a RequestContext (or the render shortcut), so the user variable isn't being passed to the context.