Im going through the “beginning Django ecommerce” book, and I am stuck on trying to show the “go to cart” link on all the pages.
I get this error: 'str' object has no attribute 'session' and the line
"{% cart_box request%}" in the HTML is highlighted with this error.
this is the HTML
{% load catalog_tags %}
<div class="cart_box">
{% cart_box request %}
</div>
{% if hour == 7 or hour == 9 or hour == 12 %}
Order time = {{hour}}
this is the view.
def menu_hour(request,hour):
#set the test cookie
request.session.set_test_cookie()
hour = int(hour)
food = Food.objects.all()
output = ', '.join([f.name for f in food])
steak = Food.objects.get(name="Steak and Egg Burrito")
steak.price = 15
steak.save()
queso = Food.objects.get(name="Queso Burrito")
queso.time = hour
food_dict = {"steak": steak, "queso": queso, "hour":hour}
return render_to_response('menu_hour.html', food_dict, context_instance=RequestContext(request))
this is the catalog tag
from django import template
from cart import cart
register = template.Library()
@register.inclusion_tag("tags/cart_box.html")
def cart_box(request):
cart_item_count = cart.cart_distinct_item_count(request)
return {'cart_item_count': cart_item_count }
this is the catalog tag HTML
{% with cart_item_count as cart_count %}
<a href="{% url show_cart %}">
Shopping Cart
<br />
{{ cart_count }} Item{{ cart_count|pluralize }}
</a>
{% endwith %}
It’s because i wasn’t passing “request” in my dictionary to the template.