$('.cart-wrap').html( 'тут дата которая пришла с сервера' );
def cart_gen(request):
categories= Category.objects.all()
products = Product.objects.filter(available=True)
cart_product_form = CartAddProductForm()
return render(request, 'shop/product/cart.html', {'product': products,'categories': categories,'cart_product_form': cart_product_form})
{% for item in cart %}
{% with product=item.product %}
<div class="main-offer_list-item">
<div class="main-offer_list-info">
<div class="main-offer_list-title">
{{ product.name }}
</div>
<div class="main-offer_list-calc">
{{item.quantity}}
</div>
</div>
<img src="{{ product.image.url }}" alt="">
<div class="main-offer_list-close">
<a class="delete-btn" data-delete="{% url 'cart:cart_remove' product.id %}"><img class="img-svg" src="{% static 'img/close.svg' %}" alt=""></a>
</div>
</div>
{% endwith %}
{% endfor %}
function getCookie(name) {
let cookieValue = null;
if (document.cookie && document.cookie !== '') {
const cookies = document.cookie.split(';');
for (let i = 0; i < cookies.length; i++) {
const cookie = cookies[i].trim();
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) === (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
const csrftoken = getCookie('csrftoken');
function csrfSafeMethod(method) {
// these HTTP methods do not require CSRF protection
return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
}
$.ajaxSetup({
beforeSend: function(xhr, settings) {
if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
xhr.setRequestHeader("X-CSRFToken", csrftoken);
}
}
});
</script>
<script>
$( ".add_to_cart" ).submit(function(addr) {
$.ajax({
type: "POST",
url: String($('.add_to_cart').data("action")),
data: {csrfmiddlewaretoken: csrftoken
},
success: function() {
$('.main-offer_list').html(`{% for item in cart %}
{% with product=item.product %}
<div class="main-offer_list-item">
<div class="main-offer_list-info">
<div class="main-offer_list-title">
{{ product.name }}
</div>
<!-- <div class="main-offer_list-calc">
1
</div> -->
</div>
<img src="{{ product.image.url }}" alt="">
<div class="main-offer_list-close">
<a href="{% url 'cart:cart_remove' product.id %}"><img class="img-svg" src="{% static 'img/close.svg' %}" alt=""></a>
</div>
</div>
{% endwith %}
{% endfor %}`);
}
});
});
Начиная с Django 2.0 подключение отличается https://docs.djangoproject.com/en/2.0/ref/urls/#path
Если у Вас более старая версия попробуйте:
from django.core.urlresolvers import reverse