yangchaojie 1 روز پیش
والد
کامیت
e903ec988f
5فایلهای تغییر یافته به همراه9 افزوده شده و 9 حذف شده
  1. 2 2
      blog/controller/article.py
  2. 1 1
      blog/router/article_url/article_url.py
  3. 2 2
      blog/views.py
  4. 2 2
      templates/category.html
  5. 2 2
      templates/index.html

+ 2 - 2
blog/controller/article.py

@@ -57,8 +57,8 @@ def new(request):
     return render(request, 'management/article/new_article.html')
 
 
-def show_article(request, title):
-    article = models.Article.objects.filter(title=title).values('id', 'title', 'intro', 'category',
+def show_article(request, pk):
+    article = models.Article.objects.filter(id=int(pk)).values('id', 'title', 'intro', 'category',
                                                                'user', 'created_time', 'type',
                                                                'cover__file_net_path',
                                                                'music__file_net_path', 'status',

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

@@ -26,7 +26,7 @@ urlpatterns = [
     path('to_edit/<pk>', article.to_edit),
     path('cancel_show_index/<pk>', article.cancel_show_index),
     path('show_show_index/<pk>', article.show_show_index),
-    path(r'<title>.html', article.show_article),
+    path(r'<pk>.html', article.show_article),
     path('edit_article', article.edit_article),
     path('delete_article', article.delete_article),
 ]

+ 2 - 2
blog/views.py

@@ -67,14 +67,14 @@ def search(request):
                         {
                             'title': item['title'],
                             'description': item['intro'],
-                            'url': '/article/{0}.html'.format(item['title'])
+                            'url': '/article/{0}.html'.format(item['id'])
                         }
                     ]
                 else:
                     result_list[item['category__name']]['results'].append({
                         'title': item['title'],
                         'description': item['intro'],
-                        'url': '/article/{0}.html'.format(item['title'])
+                        'url': '/article/{0}.html'.format(item['id'])
                     })
             return JsonResponse({'results':result_list}, safe=False)
         else:

+ 2 - 2
templates/category.html

@@ -160,7 +160,7 @@
                                         <div class="summary"><a>
                                             {{ item.user__first_name }}{{ item.user__last_name }}</a>
                                             发布了{{ item.category__name }}:<a
-                                                    href="/article/{{ item.title }}.html">{{ item.title }}</a>
+                                                    href="/article/{{ item.id }}.html">{{ item.title }}</a>
                                             {% if  is_login %}
                                                 <a title="置顶" href="/article/show_show_index/{{ item.id }}"><i
                                                         class="icon home"></i></a>
@@ -184,7 +184,7 @@
                                         <div class="summary"><a>
                                             {{ item.user__first_name }}{{ item.user__last_name }}</a>
                                             发布了{{ item.category__name }}:<a
-                                                    href="/article/{{ item.title }}.html">{{ item.title }}</a>
+                                                    href="/article/{{ item.id }}.html">{{ item.title }}</a>
                                             {% if  is_login %}
                                                 <a title="置顶" href="/article/show_show_index/{{ item.id }}"><i
                                                         class="icon home"></i></a>

+ 2 - 2
templates/index.html

@@ -25,7 +25,7 @@
                                         <div class="summary"><a>
                                             {{ item.user__first_name }}{{ item.user__last_name }}</a>
                                             发布了{{ item.category__name }}:<a
-                                                    href="/article/{{ item.title }}.html">{{ item.title }}</a>
+                                                    href="/article/{{ item.id }}.html">{{ item.title }}</a>
                                             {% if  is_login %}
                                                 <a title="取消置顶" href="/article/cancel_show_index/{{ item.id }}"><i class="icon cancel"></i></a>
                                             {% endif %}</div>
@@ -49,7 +49,7 @@
                                         <div class="summary"><a>
                                             {{ item.user__first_name }}{{ item.user__last_name }}</a>
                                             发布了{{ item.category__name }}:<a
-                                                    href="/article/{{ item.title }}.html">{{ item.title }}</a>
+                                                    href="/article/{{ item.id }}.html">{{ item.title }}</a>
                                             {% if  is_login %}
                                                 <a title="取消置顶" href="/article/cancel_show_index/{{ item.id }}"><i class="icon cancel"></i></a>
                                             {% endif %}</div>