Python 在Django中{%if user.is_autenticated%}不工作

Python 在Django中{%if user.is_autenticated%}不工作,python,django,web,django-views,django-login,Python,Django,Web,Django Views,Django Login,我在Django中创建了一个登录系统,但它无法在html文件中使用{%if user.is_autenticated%}方法。它总是以“未登录”的方式工作,而且当我登录时,我不理解问题所在。有人能帮我吗?谢谢你的帮助和支持 这是我的代码: 视图.py # Form Post class EditView(ListView): model = Article form_class = ArticleForm template_name = 'blog/form_post/

我在Django中创建了一个登录系统,但它无法在html文件中使用{%if user.is_autenticated%}方法。它总是以“未登录”的方式工作,而且当我登录时,我不理解问题所在。有人能帮我吗?谢谢你的帮助和支持 这是我的代码:

视图.py

# Form Post 
class EditView(ListView):
    model = Article
    form_class = ArticleForm
    template_name = 'blog/form_post/index.html'
    ordering = ['-data']

class AddPostView (CreateView): # Create new Post
    model = Article
    form_class = ArticleForm
    template_name = 'blog/form_post/add_post.html'

class EditPostView(UpdateView): # Edit a post
    model = Article
    form_class = ArticleForm
    template_name = 'blog/form_post/edit_post.html'

class DeletePostView(DeleteView):
    model = Article
    template_name = 'blog/form_post/delete.html'
    success_url = reverse_lazy('EditHome')
# Login 
def Slogin(request):
    if request.method == 'POST':
        username = request.POST.get('username')
        password = request.POST.get('password')
        user = authenticate(request, username = username, password = password)
        if user is not None:
            login(request, user)
            return redirect('EditHome')
        else:
            messages.info(request, 'Error')
    context = {}
    return render(request,'blog/form_post/Slogin.html' )
...
Html登录文件

{% extends 'blog/form_post/layout.html' %}
{% block title %} LogIn{% endblock title %}
{% block content %}

  <form method="POST" action="" class=" form__group">
  <h3 id="form-title" class="m-3 violet ">LOGIN</h3>
    {% csrf_token %}

    <input type="text" name="username" placeholder="Username..." class="w-75 m-3 border-top-0 border-left-0 border-right-0 bg-white">

    <input type="password" name="password" placeholder="Password..." class="w-75 m-3 border-top-0 border-left-0 border-right-0 bg-white"> <br>
    <button class="edit__button btn w-25 m-3" >Login</button>

  </form>



  {% for message in messages %}
 <h2 class="m-3 red">{{ message }}</h2>
  {% endfor %}

{% endblock content %}
{% extends 'blog/form_post/layout.html' %}
{% block title %} DashBoard{% endblock title %}
{% block content %}

{% if user.is_autenticated %}
code...
   {% else %}
   <p>You're not Admin</p>
{% endif %}
{% endblock content %}
{%extends'blog/form_post/layout.html%}
{%block title%}登录名{%endblock title%}
{%block content%}
登录
{%csrf_令牌%}

登录 {消息%中的消息为%s} {{message}} {%endfor%} {%endblock内容%}
html“索引”文件

{% extends 'blog/form_post/layout.html' %}
{% block title %} LogIn{% endblock title %}
{% block content %}

  <form method="POST" action="" class=" form__group">
  <h3 id="form-title" class="m-3 violet ">LOGIN</h3>
    {% csrf_token %}

    <input type="text" name="username" placeholder="Username..." class="w-75 m-3 border-top-0 border-left-0 border-right-0 bg-white">

    <input type="password" name="password" placeholder="Password..." class="w-75 m-3 border-top-0 border-left-0 border-right-0 bg-white"> <br>
    <button class="edit__button btn w-25 m-3" >Login</button>

  </form>



  {% for message in messages %}
 <h2 class="m-3 red">{{ message }}</h2>
  {% endfor %}

{% endblock content %}
{% extends 'blog/form_post/layout.html' %}
{% block title %} DashBoard{% endblock title %}
{% block content %}

{% if user.is_autenticated %}
code...
   {% else %}
   <p>You're not Admin</p>
{% endif %}
{% endblock content %}
{%extends'blog/form_post/layout.html%}
{%block title%}仪表板{%endblock title%}
{%block content%}
{%if user.is_autenticated%}
代码。。。
{%else%}
你不是管理员

{%endif%} {%endblock内容%}
您有一个输入错误。它应该是
用户。是否经过身份验证