How do convert a django template variable into a javascript file

hi i created a django cart funcrion i need to create a java script function when i checkout from my page my cart should be empty when i post my checkout data has been saved but my boolean variable which is defined into a view function it not accessable into java script code **checkout.html **

    if (localStorage.getItem('cart') == null) {
        var cart = {};
    } else {
        cart = JSON.parse(localStorage.getItem('cart'));
    {% if thank %}
    alert("Thanks for ordering with us. Your order id is {{id}}. Use it to track your order using our order tracker")

there thank is a variable i need when form is submit my cart should be local storage.clear()

def checkout(request):
    if request.method=="POST":
        items_json= request.POST.get('itemsJson', '')
        name=request.POST.get('name', '')
        email=request.POST.get('email', '')
        address=request.POST.get('address1', '') + " " + request.POST.get('address2', '')
        city=request.POST.get('city', '')
        state=request.POST.get('state', '')
        zip_code=request.POST.get('zip_code', '')
        phone=request.POST.get('phone', '')
        order = Order(items_json= items_json, name=name, email=email, address= address, city=city, state=state, zip_code=zip_code, phone=phone)
        update=OrderUpdate(order_id=order.order_id,update_desc='Your Order Has Been Placed')
        return render(request, 'myproj/checkout.html', {'thank':thank, 'id':id})
    return render(request, 'myproj/checkout.html')
Back to Top