【发布时间】:2019-04-14 00:34:56
【问题描述】:
以下是我在 URL.py、views.py 和 HTML 页面中的代码。但是,它返回错误:TypeError: cannot unpack non-iterable int object。
urlpatterns = [
path('', views.blogs_home, name='blogs'),
path('<int:id>', views.single_blog, name='detailed_view'),
]
我正在尝试在列表视图中捕获帖子博客的 id,以使用 id 查询从数据库中获取博客对象。以下是我的视图代码。
def single_blog(request,id):
blog_single = Blogs.objects.get(id)
context = {'blog_single': blog_single}
template = 'blog_home.html'
return render(request, template, context)
但是,正如我所提到的,它返回上述错误。
谁能解释我做错了什么
【问题讨论】:
标签: python django django-views django-urls