【问题标题】:Error - (django-taggit) - 'post_list_by_tag' with arguments '('',)' not found错误 - (django-taggit) - 'post_list_by_tag' 没有找到参数 '('',)'
【发布时间】:2020-10-18 18:41:41
【问题描述】:

学习django,找不到解决办法。添加了标签,网站给出了错误 学习django,找不到解决办法。添加了标签,网站给出了错误

list.html

        <p class="tags">
            Tags:
            {% for tag in post.tags.all %}
                <a href="{% url 'blog:post_list_by_tag' tag.slug %}">
                    {{ tag.name }}
                </a>
                {% if not forloop.last %}, {% endif %}
            {% endfor %}
        </p>
        ```


urls.py

    from django.urls import path
from . import views

app_name = 'blog'
urlpatterns = [
    # post views
    path('', views.post_list, name='post_list'),

    # path('', views.PostListView.as_view(), name='post_list'),
    path('<int:year>/<int:month>/<int:day>/<slug:post>/',views.post_detail,name='post_detail'),
    path('<int:post_id>/share/', views.post_share, name='post_share'),
    path('tag/<slug:tag_slug>/', views.post_list, name='post_list_by_tag'),
]

【问题讨论】:

  • 这意味着tag 有一个空字符串slug(或者根本没有.slug 属性。
  • 能否提供Tag的型号。
  • 感谢您的回答。明天我会在电脑前展示所有必要的东西
  • tags = TaggableManager()
  • 一切正常,直到我做了可迭代标签

标签: python django tags


【解决方案1】:

通过删除所有以前创建的不带标签的帖子解决了问题

【讨论】:

    猜你喜欢
    • 2021-03-29
    • 1970-01-01
    • 2017-08-02
    • 1970-01-01
    • 2019-03-12
    • 1970-01-01
    • 1970-01-01
    • 2014-09-13
    • 1970-01-01
    相关资源
    最近更新 更多