Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chapter 7 - issue with shop.views.product_list returning None #83

Open
gwt0083 opened this issue May 23, 2021 · 2 comments
Open

Chapter 7 - issue with shop.views.product_list returning None #83

gwt0083 opened this issue May 23, 2021 · 2 comments

Comments

@gwt0083
Copy link

gwt0083 commented May 23, 2021

After typing http://127.0.0.1:8000, I get this error:
ValueError: The view shop.views.product_list didn't return an HttpResponse object. It returned None instead.

I have verified my files against the example here and don't find any issues, they appear to match. Any suggestions, view matches
this project exactly.

Thank you,
GT

@vivekthedev
Copy link

Can you share your code?

@gwt0083
Copy link
Author

gwt0083 commented May 23, 2021

I am assuming it is the views file that is the issue, here is a cut and paste of shop-->views.py:

from django.shortcuts import render, get_object_or_404
from .models import Category, Product

def product_list(request, category_slug=None):
category = None
categories = Category.objects.all()
products = Product.objects.filter(available=True)
if category_slug:
category = get_object_or_404(Category, slug=category_slug)
products = products.filter(category=category)
return render(request, 'shop/product/list.html',
{'category': category,
'categories': categories,
'products': products})

def product_detail(request, id, slug):
product = get_object_or_404(Product, id=id, slug=slug, available=True)
return render(request, 'shop/product/detail.html',
{'product': product})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants