python - 为什么我在错误时得到 NoReverseMatch // 未找到带有参数 '('',)' 的 'post-detail' 的反向
问题描述
我找不到错误的原因。
网址.py:
path('', views.post_list, name="post_list"),
path('<str:url_sistem>/', views.post_detail, name='post-detail'),
视图.py:
def post_detail(request, url_sistem):
url_sistem = Post.objects.get(title)
posts = get_object_or_404(Post, url_sistem=url_sistem)
return render(request, 'blog/post_detail.html', {'posts':posts})
一个href链接:
<a href="{% url 'post-detail' post.url_sistem %}" style="color:black;">
解决方案
您有一个需要修复的缩进错误:
def post_detail(request, url_sistem):
url_sistem = Post.objects.get(title)
posts = get_object_or_404(Post, url_sistem=url_sistem)
return render(request, 'blog/post_detail.html', {'posts':posts})
在模板中:
<a href="{% url 'blog:post-detail' post.url_sistem %}" style="color:black;">
推荐阅读
- dockerfile - docker image websphere9问题,暴露其他端口时控制台不起作用
- python-3.x - Youtube Data API:获取总评论、喜欢、不喜欢
- android - Android 9 上的生物识别管理器
- autodesk-forge - Autodesk.Forge:未加载设计自动化 App Bundle
- symfony - Shopware 6 计划任务未运行
- python-3.x - 如何在使用 django-import-export 的 excel 导入期间避免类似的行?
- python - 如何在侧面构建这个缩放屏幕?
- sql - 在深度链接中将 jsonb 转换为 bigint 时出现问题
- session-cookies - Spring Cloud Gateway 和 Keycloak 的中间 authentication_request_not_found 错误
- c++ - 如何在 Microsoft SEAL 3.1 中使用 CRT 批处理技术?