Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django问题与html中的身份验证_Django - Fatal编程技术网

Django问题与html中的身份验证

Django问题与html中的身份验证,django,Django,为什么当我点击另一个用户配置文件上的链接时,登录选项会在顶部菜单中突出显示,好像我没有经过身份验证一样(在导航栏中,可以登录,条件{%if user.is_authenticated%}写在那里。如果我再次打开另一个页面,一切正常,则该用户已通过身份验证 导航栏 <div class=""> {% if user.is_authenticated %} <a class="navbar-brand" href="{%

为什么当我点击另一个用户配置文件上的链接时,登录选项会在顶部菜单中突出显示,好像我没有经过身份验证一样(在导航栏中,可以登录,条件{%if user.is_authenticated%}写在那里。如果我再次打开另一个页面,一切正常,则该用户已通过身份验证

导航栏

 <div class="">
  {% if user.is_authenticated %}
  <a class="navbar-brand" href="{% url 'account' %}">
    <img
      src="{{user.profile.avatar.url}}"
      alt=""
      width="50"
      height="50"
      class="d-inline-block"
    />
  </a>

  {% else %}
  <div class="signin">
    <a
      href="{% url 'login' %}"
      type="button"
      class="btn btn-primary btn-rounded"
    >
      <div class="mx-auto">login</div>
    </a>
    <a
      href="{% url 'register' %}"
      type="button"
      class="btn btn-success btn-rounded"
    >
      <div class="mx-auto">register</div>
    </a>
  </div>
转到此页面时,用户未经过身份验证

{% extends 'base/base.html' %} {% block content %}

<div>
  <h1>HELLOOOO</h1>
  {{user.user}}
</div>

{% endblock %}
{%extends'base/base.html%}{%block content%}
你好
{{user.user}}
{%endblock%}
网址

urlpatterns=[
路径(“”,views.list_users,name='list_users'),
路径('account/',views.account,name='account'),
路径('profile\u detail/',views.profile\u detail,name='profile\u detail'),

您已在上下文中传递了
user
。这是您正在查看其配置文件的用户。请在模板中选中
{%if user.is\u authenticated%}
在上下文中使用
用户
。当您想要引用当前用户以防止此类错误时,请在模板中使用
请求.user

谢谢dude,如果可以的话,我会给您1000个赞
{% extends 'base/base.html' %} {% block content %}

<div>
  <h1>HELLOOOO</h1>
  {{user.user}}
</div>

{% endblock %}
urlpatterns = [
    path('', views.list_users, name='list_users'),
    path('account/', views.account, name='account'),
    path('profile_detail/<int:pk>/', views.profile_detail, name='profile_detail'),