I want to print the data received in the post request on cart_change_form.html, but I have not been able to solve it for a few days.
It was confirmed that the data came in normally up to the changeform_view of admin.py, but only empty values, the data before the POST request, are displayed in cart_change_form.html.
Please tell me how can i print the data after POST request to cart_change.form.html.
#admin.py
def changeform_view(self, request, object_id=None, form_url='', extra_context=None):
extra_context = {'title': 'Cart Add'}
extra_context['show_save_and_add_another'] = False
if request.method == 'POST':
data = json.loads(request.body)
extra_context['data'] = data
print(extra_context['data']) # I successfully got data here
return super(CartAdmin, self).changeform_view(request, object_id, form_url, extra_context=extra_context)
#cart_change_form.html
{% extends 'admin/change_form.html' %}
{% url 'admin:app_list' app_label=opts.app_label %}
{% load i18n admin_urls static admin_modify jazzmin %}
{% get_jazzmin_settings request as jazzmin_settings %}
{% block cart_extrajs %}
<script type="text/javascript">
if("{{ data }}"){ # empty value is returned
alert("hi");
}
</script>
{% endblock %}