{% if viewMode == 1 %}
{{viewMode}}
AJAX request with POST method
{% elif viewMode == 0 %}
{{viewMode}}
Non-AJAX request or GET method
{% else %}
Unknown request type
{% endif %}
{% endblock content %}
is_ajax = request.headers.get('X-Requested-With') == 'XMLHttpRequest'
print(is_ajax)
print("is_ajax")
if is_ajax:
print("saaaaassss")
if request.method == 'POST':
print("POSTPOSTPOSTPOSTPOST")
data = json.load(request)
print("POSTPOSTPOSTPOSTPOST")
print('Request body:', data)
print("poss====")
aa = data['pos']
print(aa)
ss = aa['lng']
print(ss)
data = {
'viewMode': 0,
}
# get the current value of the label from the POST data
current_value = int(request.POST.get('current_value', 0))
# increment the value of the label by 1
new_value = current_value + 1
# render0. the template with the updated value
# if request.method == 'POST':
# # request_body = request.body.decode('utf-8')
# data = json.load(request)
# d=data.get('pos')
#
# print('Request body:', d)
# print("lng====")
# aa=d['lng']
# print(aa)
# response_data = {'status': 200, 'message': 'All is Good!', 'redirect': '/search2/'}
return render(request,'search.html',{'current_value': new_value,'viewMode': 1})
else:
data = {
'viewMode': 1,
}
return render(request,'search.html' ,{'current_value': 0,'viewMode': 0})
یک تابع تعریف کردم داخل تایع داده دارم گفتم اگر درست بود در این صفحه بعد نمایش بدهد در غیر این صورت در همین صفحه بمانه یک مثالی یا رفرنس خوب معرفی منید ممنون میشم