3๐
I think you have a bit of a misconception about how your django application communicates with your client. You have to understand the request response lifecycle.
Your template context does only exist inside the request response lifecycle. Every request from your client will start a new worker with a new template context to generate a response. There is no persistent stateful connection between your client application and django.
That means that if you want to update your client side page without reloading it (requesting it again) you have to pass the new card count with your JsonResponse
to the client and let the javascript code that handles the response update the displayed value.
2๐
You can not. Once the page have been rendered, all template variables disappear. You can use an input hidden
to store the cart.count
value, and then update that value.
- [Django]-Extend Django's ManyToManyField with custom fields
- [Django]-Django โ Save modelForm even if no field are changed on POST
- [Django]-CSRF Middleware โ change csrf_token output (from xHTML to HTML)
- [Django]-Csrf_exempt not working with django auth
- [Django]-Python chained comparison