detail.html 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. {% extends "base.html" %}
  2. {% load static %}
  3. {% block title %}
  4. 文章详情:{{ article.title }}
  5. {% endblock title %}
  6. {% block content %}
  7. <div class="container">
  8. <div class="row">
  9. <div class="col-3 mt-4">
  10. <h4><strong>目录</strong></h4>
  11. <hr>
  12. <div>
  13. {{ tor|safe }}
  14. </div>
  15. </div>
  16. <div class="col-9">
  17. <h1 class="mt-4 mb-4">
  18. {{ article.title }}
  19. </h1>
  20. <div class="col-12 alert alert-success">
  21. 作者: {{ article.author }}
  22. {% if user == article.author %}
  23. · <a href="#" onclick="confirm_delete()">
  24. 删除文章
  25. </a>
  26. · <a href="{% url 'article:article_update' article.id %}">
  27. 编辑文章
  28. </a>
  29. {% endif %}
  30. <div>
  31. 浏览:{{ article.total_views }}
  32. </div>
  33. <form style="display: none"
  34. id="safa_delete"
  35. action="{% url 'article:article_safe_delete' article.id %}"
  36. method="post"
  37. >
  38. {% csrf_token %}
  39. <button type="submit">
  40. 发送
  41. </button>
  42. </form>
  43. </div>
  44. <div class="col-12">
  45. <p>
  46. {{ article.body|safe }}
  47. </p>
  48. </div>
  49. <hr>
  50. {% if user.is_authenticated %}
  51. <div>
  52. <form action="{% url 'comment:post_comment' article.id %}" method="post">
  53. {% csrf_token %}
  54. <div class="form-group">
  55. <label for="body">
  56. <strong>
  57. 发表评论
  58. </strong>
  59. </label>
  60. <textarea type="text" class="form-control" id="body" name="body" rows="2"></textarea>
  61. </div>
  62. <button type="submit" class="btn btn-primary">发送</button>
  63. </form>
  64. </div>
  65. <br>
  66. {% else %}
  67. <br>
  68. <h5 class="row justify-content-center">
  69. 请<a href="{% url 'userprofile:login' %}">登录</a>后回复
  70. </h5>
  71. <br>
  72. {% endif %}
  73. <h4>共有{{ comments.count }}条评论</h4>
  74. <div>
  75. {% for comment in comments %}
  76. <hr>
  77. <p>
  78. <strong style="color: pink">
  79. {{ comment.user }}
  80. </strong>于
  81. <span style="color: green">
  82. {{ comment.created|date:"Y-m-d H:i:s" }}
  83. </span>时评论道:
  84. </p>
  85. <pre style="font-family: inherit;font-size: 1em;">
  86. {{ comment.body }}
  87. </pre>
  88. {% endfor %}
  89. </div>
  90. </div>
  91. </div>
  92. </div>
  93. <script>
  94. function confirm_delete() {
  95. layer.open({
  96. title: "删除文章",
  97. content: "确认删除这篇文章吗?",
  98. yes: function (index, layero) {
  99. $('form#safe_delete button').click();
  100. layer.close(index);
  101. },
  102. })
  103. }
  104. </script>
  105. {% endblock content %}