header.html 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <!-- 定义导航栏 -->
  2. <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
  3. <div class="container">
  4. <!-- 导航栏商标 -->
  5. <a class="navbar-brand" href="#">我的博客</a>
  6. <!-- 导航入口 -->
  7. <div>
  8. <ul class="navbar-nav">
  9. <!-- 条目 -->
  10. <li class="nav-item">
  11. <a class="nav-link" href="{% url 'article:article_create' %}">写文章</a>
  12. </li>
  13. <li class="nav-item">
  14. <a class="nav-link" href="{% url 'article:article_list' %}">文章</a>
  15. </li>
  16. <!-- Django的 if 模板语句 -->
  17. {% if user.is_authenticated %}
  18. <!-- 如果用户已经登录,则显示用户名下拉框 -->
  19. <li class="nav-item dropdown">
  20. <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button"
  21. data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  22. {% if unread_count %}
  23. <svg viewBox="0 0 8 8"
  24. width="8px"
  25. height="8px">
  26. <circle cx="4" cy="4" r="4" fill="#ff6b6b"></circle>
  27. </svg>
  28. {% endif %}
  29. {{ user.username }}
  30. </a>
  31. <div class="dropdown-menu" aria-labelledby="navbarDropdown">
  32. <!--通知的计数-->
  33. <a class="dropdown-item" href="{% url 'notice:list' %}">通知
  34. {% if unread_count %}
  35. <span class="badge badge-danger">{{ unread_count }}</span>
  36. {% endif %}
  37. </a>
  38. <a class="dropdown-item" href="{% url 'userprofile:edit' user.id %}">个人信息</a>
  39. <a class="dropdown-item" href="{% url 'userprofile:logout' %}">退出登录</a>
  40. <a class="dropdown-item" href="#" onclick="user_delete()">删除用户</a>
  41. </div>
  42. {% if user.is_authenticated %}
  43. <form
  44. style="display:none;"
  45. id="user_delete"
  46. action="{% url 'userprofile:delete' user.id %}"
  47. method="POST"
  48. >
  49. {% csrf_token %}
  50. <button type="submit">发送</button>
  51. </form>
  52. <script>
  53. function user_delete() {
  54. // 调用layer弹窗组件
  55. layer.open({
  56. title: "删除用户",
  57. content: "确认删除用户资料吗?",
  58. yes: function (index, layero) {
  59. $('form#user_delete button').click();
  60. layer.close(index);
  61. },
  62. })
  63. }
  64. </script>
  65. {% endif %}
  66. </li>
  67. <!-- 如果用户未登录,则显示 “登录” -->
  68. {% else %}
  69. <li class="nav-item">
  70. <a class="nav-link" href="{% url 'userprofile:login' %}">登录</a>
  71. </li>
  72. <!-- if 语句在这里结束 -->
  73. {% endif %}
  74. </ul>
  75. </div>
  76. </div>
  77. </nav>