[Fixed]-TypeError: cannot unpack non-iterable int object in Django views function

29👍

You should specify the name of the parameter in .filter(…) [Django-doc] or .get(…) [Django-doc] calls:

def single_blog(request, id):
   blog_single = Blogs.objects.get(id=id)
   context = {'blog_single': blog_single}
   template = 'blog_home.html'

   return render(request, template, context)

I also propose to rename your variable to something else (so both in the urls.py and views.py), since id is a builtin function, and now a local variable is "hiding" this builtin.

Leave a comment