简体   繁体   中英

why django returns me a template Error for this case {% if user.is_authenticated %}?

i would like to add on my django template main page interface a condition but it return me this error:

ProgrammingError at /

relation "django_session" does not exist LINE 1: ...ession_data", "django_session"."expire_date" FROM "django_se...

ther is the Template code:

...

{% extends '_base.html' %}

{% block title %}Home Page{% endblock title %}

{% block content %}
    <h2>Homepage</h2>
    {% if user.is_authenticated %}
        <p>Hi {{ user.email }}</p>
    {% else %}
        <p>You are not Loged</p>
        <p><a href="{% url 'login' %}">Log In</a> </p>
    {% endif %}
{% endblock content %}

... thamk you for your answers

You have not migrated your models to the database.

If you have created a custom user class, run the below command for creating the migration file .

python manage.py makemigrations

If you have already run the migrations, you need to run the migrate commands so as to convert the migration files into the database schema.

python manage.py migrate

Hopefully, that will solve your problem

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM