'Code running in local does not work on server (Django)
I created a List in views.py to draw a chart in html. In local PC, the chart is printed well whenever connected. But on the server PC, "Cannot resolve keyword 'jan' into field." An error occurs. I wondered if the indent of the for statement was a problem, but it works fine in local without any problem. But, If I proceed with "sudo systemctl daemon-reload" -> "sudo systemctl restart wsgi" on the server PC, For a few minutes the chart is printed normally. However, when I access the page again after a while The above error occurs. I really don't know what's wrong. Please help...
[views.py]
team_parameter = request.GET.get('team')
monthly_kwargs = {}
for i in range(1, 13):
gte = datetime(today.year, i, 1)
lte = get_last_day_of_month(date(today.year, i, 1))
mo = f'{gte:%b}'.lower()
monthly_kwargs[mo] = Count('student_id', filter=Q(date__gte=f'{gte:%Y-%m-%d}', date__lte=f'{lte:%Y-%m-%d}'))
monthly_kwargs['SPECIAL_' + mo] = Count('student_id', filter=Q(date__gte=f'{gte:%Y-%m-%d}', date__lte=f'{lte:%Y-%m-%d}', student__class__id__in=special))
monthly_kwargs['total'] = Count('student_id', filter=Q(date__year=today.year))
monthly_kwargs['SPECIAL_total'] = Count('student_id', filter=Q(date__year=today.year))
value_list_args = ['uploader_id__first_name', 'jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec', 'total', 'SPECIAL_jan', 'SPECIAL_feb', 'SPECIAL_mar', 'SPECIAL_apr', 'SPECIAL_may', 'SPECIAL_jun', 'SPECIAL_jul', 'SPECIAL_aug', 'SPECIAL_sep', 'SPECIAL_oct', 'SPECIAL_nov', 'SPECIAL_dec', 'SPECIAL_total']
if not request.GET or parameter == 'ALL':
monthly_register = Memo.objects \
.annotate(**monthly_kwargs) \
.values_list(*value_list_args) \
else:
monthly_register = Memo.objects \
.annotate(**monthly_kwargs) \
.values_list(*value_list_args) \
monthly_register_list = [list(i)[0:27] for i in monthly_register]
return render(request, 'chart.html', {'team': team_parameter, 'monthly_register_list': monthly_register_list})
[chart.html]
<form class="mt-2" action="/chart" method="GET">
<select name="team" id="team">
<option value="ALL" {% if team == "ALL" %} selected {% endif %}>ALL</option>
<option value="A" {% if team == "A" %} selected {% endif %}>A</option>
<option value="B" {% if team == "B" %} selected {% endif %}>B</option>
<option value="C" {% if team == "C" %} selected {% endif %}>C</option>
</select>
<button class="btn btn-primary btn-xs" type="submit">Check</button>
</form>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
