Hi everyone,
I am still very new to Django and having trouble creating a URL pattern to a view in my app ‘carts’.
the view is defined in carts.views as view:
def view(request):
cart = Cart.objects.all()[0]
context = {“cart”: cart}
template = “cart/view.html”
return render(request, template, context)
After importing view from carts.views, I’ve tried adding the URL pattern:
path(‘cart/’, view())
But this does not work as view() requires the argument identifying request due to the render shortcut used in the return statement.
Reading docs for render, I’ve learned that request is the request object used to generate the response, but I am not entirely sure what this means. Reading docs for request and response objects, I am not sure if it would be a good idea (or even possible) to set a default value.
Can anyone help me by providing a better solution to what I am trying to do? This seems like a common task and I suspect I have gone about it in the wrong way.
Thank you in advance for your time!