header.html 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. {% load static %}
  2. <head>
  3. <link rel="stylesheet" href="{% static 'header.css' %}">
  4. </head>
  5. <!-- 定义导航栏 -->
  6. <nav class="navbar navbar-expand-lg navbar-light fixed-top" id="mainNav">
  7. <div class="container">
  8. <!-- 导航栏商标 -->
  9. <a class="navbar-brand" href="{% url 'home' %}">Shellmiao's Blog</a>
  10. <button class="navbar-toggler collapsed" type="button" data-toggle="collapse" data-target="#navbarDefault"
  11. aria-controls="navbarDefault" aria-expanded="false" aria-label="Toggle navigation">
  12. <span></span>
  13. <span></span>
  14. <span></span>
  15. </button>
  16. <!-- 导航入口 -->
  17. <div class="navbar-collapse collapse justify-content-end" id="navbarDefault">
  18. <ul class="navbar-nav">
  19. <li class="nav-item">
  20. <form action="{% url 'article:article_list' %}">
  21. <div class="search">
  22. <label>
  23. <input name="search" type="search" class="search-box"/>
  24. </label>
  25. <span class="search-button">
  26. <span class="search-icon">
  27. </span>
  28. </span>
  29. </div>
  30. </form>
  31. </li>
  32. <!-- 条目 -->
  33. <li class="nav-item">
  34. <a class="nav-link" href="{% url 'article:article_create' %}">Publish An Article</a>
  35. </li>
  36. <li class="nav-item">
  37. <a class="nav-link" href="{% url 'article:article_list' %}">Articles</a>
  38. </li>
  39. <!-- Django的 if 模板语句 -->
  40. {% if user.is_authenticated %}
  41. <!-- 如果用户已经登录,则显示用户名下拉框 -->
  42. <li class="nav-item dropdown">
  43. <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button"
  44. data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  45. {% if unread_count %}
  46. <svg viewBox="0 0 8 8"
  47. width="8px"
  48. height="8px">
  49. <circle cx="4" cy="4" r="4" fill="#ff6b6b"></circle>
  50. </svg>
  51. {% endif %}
  52. {{ user.username }}
  53. </a>
  54. <div class="dropdown-menu" aria-labelledby="navbarDropdown">
  55. <!--通知的计数-->
  56. {# <a class="dropdown-item" href="{% url 'notice:list' %}">Notice#}
  57. {# {% if unread_count %}#}
  58. {# <span class="badge badge-danger">{{ unread_count }}</span>#}
  59. {# {% endif %}#}
  60. {# </a>#}
  61. {# <a class="dropdown-item" href="{% url 'userprofile:edit' user.id %}">Profile</a>#}
  62. <a class="dropdown-item" href="{% url 'userprofile:logout' %}">Logout</a>
  63. <a class="dropdown-item" href="#" onclick="user_delete()">Delete Account</a>
  64. </div>
  65. {% if user.is_authenticated %}
  66. <form
  67. style="display:none;"
  68. id="user_delete"
  69. action="{% url 'userprofile:delete' user.id %}"
  70. method="POST"
  71. >
  72. {% csrf_token %}
  73. <button type="submit">发送</button>
  74. </form>
  75. <script>
  76. function user_delete() {
  77. // 调用layer弹窗组件
  78. layer.open({
  79. title: "删除用户",
  80. content: "确认删除用户资料吗?",
  81. yes: function (index, layero) {
  82. $('form#user_delete button').click();
  83. layer.close(index);
  84. },
  85. })
  86. }
  87. </script>
  88. {% endif %}
  89. </li>
  90. <!-- 如果用户未登录,则显示 “登录” -->
  91. {% else %}
  92. <li class="nav-item">
  93. <a class="nav-link" href="{% url 'account_login' %}">Login</a>
  94. </li>
  95. <!-- if 语句在这里结束 -->
  96. {% endif %}
  97. </ul>
  98. </div>
  99. </div>
  100. </nav>