header.html 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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="#">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. <!-- 条目 -->
  20. <li class="nav-item">
  21. <a class="nav-link" href="{% url 'article:article_create' %}">Publish An Article</a>
  22. </li>
  23. <li class="nav-item">
  24. <a class="nav-link" href="{% url 'article:article_list' %}">Articles</a>
  25. </li>
  26. <!-- Django的 if 模板语句 -->
  27. {% if user.is_authenticated %}
  28. <!-- 如果用户已经登录,则显示用户名下拉框 -->
  29. <li class="nav-item dropdown">
  30. <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button"
  31. data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  32. {% if unread_count %}
  33. <svg viewBox="0 0 8 8"
  34. width="8px"
  35. height="8px">
  36. <circle cx="4" cy="4" r="4" fill="#ff6b6b"></circle>
  37. </svg>
  38. {% endif %}
  39. {{ user.username }}
  40. </a>
  41. <div class="dropdown-menu" aria-labelledby="navbarDropdown">
  42. <!--通知的计数-->
  43. <a class="dropdown-item" href="{% url 'notice:list' %}">Notice
  44. {% if unread_count %}
  45. <span class="badge badge-danger">{{ unread_count }}</span>
  46. {% endif %}
  47. </a>
  48. <a class="dropdown-item" href="{% url 'userprofile:edit' user.id %}">Profile</a>
  49. <a class="dropdown-item" href="{% url 'userprofile:logout' %}">Logout</a>
  50. <a class="dropdown-item" href="#" onclick="user_delete()">Delete Account</a>
  51. </div>
  52. {% if user.is_authenticated %}
  53. <form
  54. style="display:none;"
  55. id="user_delete"
  56. action="{% url 'userprofile:delete' user.id %}"
  57. method="POST"
  58. >
  59. {% csrf_token %}
  60. <button type="submit">发送</button>
  61. </form>
  62. <script>
  63. function user_delete() {
  64. // 调用layer弹窗组件
  65. layer.open({
  66. title: "删除用户",
  67. content: "确认删除用户资料吗?",
  68. yes: function (index, layero) {
  69. $('form#user_delete button').click();
  70. layer.close(index);
  71. },
  72. })
  73. }
  74. </script>
  75. {% endif %}
  76. </li>
  77. <!-- 如果用户未登录,则显示 “登录” -->
  78. {% else %}
  79. <li class="nav-item">
  80. <a class="nav-link" href="{% url 'userprofile:login' %}">Login</a>
  81. </li>
  82. <!-- if 语句在这里结束 -->
  83. {% endif %}
  84. </ul>
  85. </div>
  86. </div>
  87. </nav>