CJ 1 gadu atpakaļ
vecāks
revīzija
1cfe017696

+ 8 - 0
blog/controller/article.py

@@ -38,6 +38,14 @@ def draft(request):
     return render(request, 'management/article/draft.html', context={'articles': articles})
 
 
+@login_required(login_url='/login')
+def cancel_show_index(request, pk):
+    article = models.Article.objects.get(id=int(pk))
+    article.is_top = False
+    article.save()
+    return HttpResponseRedirect('/')  # 跳转到主界面
+
+
 def new(request):
     return render(request, 'management/article/new_article.html')
 

+ 1 - 0
blog/router/article_url/article_url.py

@@ -24,6 +24,7 @@ urlpatterns = [
     path('add_article', article.add_article),
     path('get_all_article', article.get_all_article),
     path('to_edit/<pk>', article.to_edit),
+    path('cancel_show_index/<pk>', article.cancel_show_index),
     path(r'<pk>.html', article.show_article),
     path('edit_article', article.edit_article),
     path('delete_article', article.delete_article),

+ 6 - 2
templates/index.html

@@ -34,7 +34,7 @@
                                             {% endfor %}</div>
                                     </div>
                                 </div>
-                            {% elif item.type == 2 and item.is_top%}
+                            {% elif item.type == 2 and item.is_top %}
                                 <div class="event">
                                     <div class="label">
                                         <img src="/user_avatar/{{ item.user_id }}">
@@ -45,7 +45,11 @@
                                         <div class="summary"><a>
                                             {{ item.user__first_name }}{{ item.user__last_name }}</a>
                                             发布了{{ item.category__name }}:<a
-                                                    href="/article/{{ item.id }}.html">{{ item.title }}</a></div>
+                                                    href="/article/{{ item.id }}.html">{{ item.title }}</a>
+                                            {% if  is_login %}
+                                                <a href="/article/cancel_show_index/{{ item.id }}"><i class="icon cancel"></i></a>
+                                            {% endif %}</div>
+
                                         {% if '<iframe' in item.intro %}
                                             {% autoescape off %}
                                                 <div class="extra images">