Search code examples
djangoregistrationdjango-registration

django-registration Template not showing user logged in


I am using the current version of django and using django-registration

I got everything working on the server, and I got the templates done, with the help of this blog.

sometimes the page show's the user logged in, other times the same base.html say's that the user is not logged in. I think I have to pass the user to the template but I have no idea what to lookup, the docs on this stop after it's set up. How can I get this Base.html to work, It say's that I'm not logged in. then I go to the loggin page and it then say's on that page that I am logged in.

It seems to be url specific. It will say that I am logged in, move to a different page, and it offers me to get logged in. Why can't I have it site wide, what am I missing

django-registration is a package so I don't know what I can do, Change the view Function? the following is my base.html

 {% load i18n %}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
    <link rel="stylesheet" href="/style.css" />
    <title>{% block title %}User test{% endblock %}</title>


</head>

<body>
    <div id="header">
        {% block header %}
    {% if user.is_authenticated %}
    {% trans "Logged in" %}: {{ user.username }} 
    (<a href="{% url auth_logout %}">{% trans "Log out" %}</a> | 
    <a href="{% url auth_password_change %}">{% trans "Change password" %}</a>)
    {% else %}
    <a href="{% url auth_login %}">{% trans "Log in" %}</a>
    {% endif %}
    <hr />
        {% endblock %}
    </div>


    <div id="content">
        {% block content %}{% endblock %}
    </div>

    <div id="footer">
        {% block footer %}
        <hr />
        {% endblock %}
    </div>
</body>

</html>

Solution

  • You didn't post the view code but I suspect that your issue relates to the fact that you didnt pass a RequestContext on all of your views functions.

    The User variable in the templete is added by a context processor.

    just do :

    ctx = RequestContext(request)
    

    in your view function and pass it to the templete processor by :

    context_instance=ctx