I have a quiz app and there are lots of interactions between JavaScript in templates and django views. Normally, on decent enough internet connection and less traffic the code works as it is supposed to. But as soon as the internet is slow and traffic is high (ie. 20 or so people are taking a quiz at the same time) . Django views stop catching values sent from forms in template Here is an example: Template code
<form action='{% url "QuestionsAndPapers:EvaluateTest" %}' method='post' id ='finishForm'>
{%csrf_token%}
<input type="text" name="timeTaken" value="" class='hidden' />
<button type="submit" id='testsub' value="{{te_id}}" class="btn btn-default text-center" name="testSub" onclick="formClick()" >Submit Test</button>
</form>
Django View:
def evaluate_test(request):
user = request.user
me = Studs(user)
if 'testSub' in request.POST:
# get values of test id and total test time
try:
test_id = request.POST['testSub']
test_id = int(test_id)
Now the problem is majority of times the template successfully returns {{te_id}} variable but when traffic is high and internet is slow evaluate_test function can't catch the {{te_id}} variable and it throws an error
ValueError: invalid literal for int() with base 10:
The problem is this error is not reproducible.