Hi Carl,

The problem seems to be the use of `get_template`:
https://docs.djangoproject.com/en/2.1/topics/templates/#usage

The second parameter (the one you're using a dict) is not the values to
pass to the template, but the name of the template engine to be used.

I'd suggest using `render` (
https://docs.djangoproject.com/en/2.1/topics/http/shortcuts/#render)
instead, which is more common than trying to get a template from a specific
loader.

On Tue, Sep 4, 2018 at 2:37 AM, carl collins <[email protected]>
wrote:

> Here is the code for view.py in my cart app  please help(also see the
> screenshot):
>
>
> from django.template import loader
> from django.http import HttpResponse
> from django.template.loader import render_to_string
> import django.template.loader
>
>
> from cart.cart import Cart
> from .models import Product
> '''from cart.models import Category, Product'''
>
>
> #gallery    default view
> def index(request):
>     #prepare the models
>     #        empty
>     #prepare the template
>     template = loader.get_template('templates/cart.html',
> dict(cart=Cart(request))  )
>     #prepare the context
>     context = {'request':request}
>     return HttpResponse(template.render(context, request))
>
> def add_to_cart(request, product_id, quantity):
>     product = Product.objects.get(id=product_id)
>     cart = Cart(request)
>     cart.add(product, product.unit_price, quantity)
>
> def remove_from_cart(request, product_id):
>     product = Product.objects.get(id=product_id)
>     cart = Cart(request)
>     cart.remove(product)
>
>
> def get_cart(request):
>
>     template = loader.get_template('templates/cart.html', dict(cart =
> Cart(request)))
>
>     #prepare the context
>     context = {'request':request}
>     return HttpResponse(template.render(context, request))
>     return HttpResponse(template.render(context, request))
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/a78552f7-9973-456d-b0d5-79602f4bbf5c%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/a78552f7-9973-456d-b0d5-79602f4bbf5c%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
*Julio Biason*, Sofware Engineer
*AZION*  |  Deliver. Accelerate. Protect.
Office: +55 51 3083 8101 <callto:+555130838101>  |  Mobile: +55 51
<callto:+5551996209291>*99907 0554*

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEM7gE1y54BKXnbmdkx72ew32HhtUBkV-0uPJPQ8pqiq8VRoqA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to