python - Django Web App Code works on local dev machine but not when deployed to server -


i have django web project working on overall has gone pretty smoothly. have view below grabs objects database , displays them via template user.

def index(request):     all_occurrences = occurrence.objects.all().order_by("-pk")     calculate_percentage_right()      context = {         'all_occurrences': all_occurrences,         'percentage_right': calculate_percentage_right()     }     query = request.get.get("q")     if query:         all_occurrences = all_occurrences.filter(             q(subject__icontains=query) |             q(details__icontains=query))         return render(request, 'wrong/wrong_view.html', {             'all_occurrences': all_occurrences,         })     else:         return render(request, 'wrong/wrong_view.html', context) 

the issue occurring me makes no sense me using function calculate percentage right based on object attribute called "timewrong". when run on local machine performs expected, when deploy web server hosted on amazon ec2 instance not calculate percentage correctly. either 100% or 0% no in between.

i have verified on webserver seeing of variables have created correctly. problems appears occur when division happens me percentage.

def calculate_percentage_right():     wrongs = occurrence.objects.all()     total_minutes_wrong = 0      wrong in wrongs:         total_minutes_wrong += wrong.timewrong      minutes_in_year = 525600     minutes_right = minutes_in_year - total_minutes_wrong     percentage_right = (minutes_right / minutes_in_year) * 100      return percentage_right 

the app being deployed via distelli server, other aspects of program working should. can't quite understand how works on local machine , not on web server.

i'd check python version on webserver. 1 way see happening if using python 3 locally , python 2 on server.

the behaviour of division operator changed as described here. silently floor results of integer divisions less 1, giving result 0.

the other way percentage_right evaluate 0 if minutes_right equal 0. seems unlikely unless you've created case on purpose in test data.

the 100% results saw explained either there being no results query wrongs = occurrence.objects.all() or of results having value of 0 wrong.timewrong.

tl;dr either python version mismatch or data isn't you're expecting on webserver.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -