detail.html 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. {% if article.avatar %}
  45. <div class="row mt-2">
  46. <img src="{{ article.avatar.url }}"
  47. alt="avatar"
  48. style="max-width: 100%; border-radius: 20px;"
  49. >
  50. </div>
  51. <hr/>
  52. {% endif %}
  53. <div class="col-12">
  54. <p>
  55. {{ article.body|safe }}
  56. </p>
  57. </div>
  58. <hr>
  59. {% if user.is_authenticated %}
  60. <div>
  61. <form action="{% url 'comment:post_comment' article.id %}" method="post">
  62. {% csrf_token %}
  63. <div class="form-group">
  64. <label for="body">
  65. <strong>
  66. 发表评论
  67. </strong>
  68. </label>
  69. <!--<textarea type="text" class="form-control" id="body" name="body" rows="2"></textarea>-->
  70. <div>
  71. {{ comment_form.media }}
  72. {{ comment_form.body }}
  73. </div>
  74. </div>
  75. <button type="submit" class="btn btn-primary">发送</button>
  76. </form>
  77. </div>
  78. <br>
  79. {% else %}
  80. <br>
  81. <h5 class="row justify-content-center">
  82. 请<a href="{% url 'userprofile:login' %}">登录</a>后回复
  83. </h5>
  84. <br>
  85. {% endif %}
  86. <h4>共有{{ comments.count }}条评论</h4>
  87. <div>
  88. {% for comment in comments %}
  89. <hr>
  90. <p>
  91. <strong style="color: pink">
  92. {{ comment.user }}
  93. </strong>于
  94. <span style="color: green">
  95. {{ comment.created|date:"Y-m-d H:i:s" }}
  96. </span>时评论道:
  97. </p>
  98. <pre style="font-family: inherit;font-size: 1em;">
  99. {{ comment.body|safe }}
  100. </pre>
  101. {% endfor %}
  102. </div>
  103. </div>
  104. </div>
  105. </div>
  106. <script>
  107. function confirm_delete() {
  108. layer.open({
  109. title: "删除文章",
  110. content: "确认删除这篇文章吗?",
  111. yes: function (index, layero) {
  112. $('form#safe_delete button').click();
  113. layer.close(index);
  114. },
  115. })
  116. }
  117. </script>
  118. <script src="{% static 'ckeditor/ckeditor/plugins/prism/lib/prism/prism_patched.min.js' %}"></script>
  119. <link rel="stylesheet" href="{% static 'prism/prism.css' %}">
  120. {% endblock content %}
  121. {% block script %}
  122. <script>
  123. $(".django-ckeditor-widget").removeAttr('style');
  124. </script>
  125. {% endblock script %}