Answer the question
In order to leave comments, you need to log in
How to do an add to cart from a shared directory?
Hello.
There is an addition of a product in a detailed review of the product:
#views.py
def ProductDetail(request, id, slug):
product = get_object_or_404(Product, id=id, slug=slug, available=True)
cart_product_form = CartAddProductForm()
return render_to_response('catalog/allCatalog/BaseProduct.html',
{'product': product,
'cart_product_form': cart_product_form})
<form action="{% url 'cart:CartAdd' product.id %}" method="post">
<label class="cart_quantity" for="id_quantity">Количество:</label>
{% csrf_token %}
{{ cart_product_form }}
<input class="product_details_basket vcenter text-center" type="submit" value="Добавить в корзину">
</form>
class catalog_infrared(ListView):
model = Product
template_name = 'catalog/product_list.html'
context_object_name = 'product' # Default: object_list
paginate_by = 9
queryset = Product.objects.all().order_by('price').filter(category__name='Теплый пол', categorysub__name='пленочный')
class catalog_mats_devi(ListView):
model = Product
template_name ='catalog/product_list.html'
context_object_name = 'product' # Default: object_list
paginate_by = 9
queryset = Product.objects.all().order_by('price').filter(category__name='Теплый пол', categorysub__name='нагревательный мат', brand__name='Devi')
[21/May/2018 21:04:17] "POST /cart/add/38/ HTTP/1.1" 302 0
[21/May/2018 21:04:17] "GET /cart/ HTTP/1.1" 200 4349
Answer the question
In order to leave comments, you need to log in
Most likely, and even better, add to the cart not through the form, but through ajax! In other words - via javascript using the POST or PUT method with the transfer in the JSON body
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question