2👍
✅
First learn Javascript and Jquery and Ajax to understand more clearly.
http://www.tutorialspoint.com/jquery/
http://www.w3schools.com/jquery/
template ‘event.html’:
{% if user in event.users.all %}
<form action="/event/{{ event.id }}/" method="GET" id="event">
{% csrf_token %}
<input type="hidden" value="{{ event.id }}" name="remove">
<input type="submit" class="btn btn-warning btn-block" value="{% trans "Remove from My Events"%}">
</form>
{% else %}
<form action="/event/{{ event.id }}/" method="GET">
{% csrf_token %}
<input type="hidden" value="{{ event.id }}" name="add">
<input type="submit" class="btn btn-primary btn-block" value="{% trans "Add to My Events"%}">
</form>
{% endif %}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-beta1/jquery.min.js"></script>
<script>
$('#event').submit(function(e){
e.preventDefault();
url = $(this).attr('action') # to get url
data = $(this).serialize(); # for sending form data
$.post(url, data, function(response){
# do whatever you want with response(data)
})
})
</script>
0👍
It is impossible, Python is a server side language and if you want to process data, you need send the information to the server.
The first time that i did this, i saw this video in YouTube: https://www.youtube.com/watch?v=KgnPSmrQrXI
- [Answered ]-Django template cannot access JSON Key in duplicate quotations: {" 'Key' ": " Value "}
- [Answered ]-Checking boxes for items passed through context in Django
- [Answered ]-Python ImportError: No module named djng
Source:stackexchange.com