I have a function in views.py which takes input (through the post-request on an HTML page) and appends it to a list and then returns the newly appended list. Upon submitting, the whole page refreshes. I have a background element (a video on a loop).
In my HTML file, I have changed the button type from type="submit" to type="button", which prevents the page from re-loading and continues to play background video correctly. However, it doesn't seem to run my main function. I thought maybe using type="button" and then making a to run the function might work, but I might be wrong on that. I have read solutions others have posted with Javascript and AJAX; I tried to copy and paste some but without success. I am new to programming and would really appreciate feedback and help! Thanks Tobias
in views.py :
def test5(request):
pd = [8, 24, 'kb']
user_data = {}
if request.method == 'POST':
x = request.POST.get('x')
pd.append(x)
return render(request,'app/test5.html',{'data': pd})
in test5.html :
{% extends 'app/testbase.html' %} <!-- this brings in my background video -->
{% block content %}
This is a test<br>
[8, 24, 'kb'] <br>
<script>
function click_action() {
}
</script>
<form method="post" action="/app/test5/" id="post-form">
{% csrf_token %}
<input name="x" placeholder="Enter number" value="" required autofocus>
<button onclick="click_action()" name="start_button" id="myBtn" type="submit">add to list </button>
</form>
{{ data }}
{% endblock %}
I would like to get the newly appended list (pd) printed on the screen without the page being refreshed after hitting the button. Thanks for the help!!!!