Skip to content
This repository has been archived by the owner on Oct 16, 2019. It is now read-only.

Django hometast v3.0 #5

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Update views.py
  • Loading branch information
AleksandrTsimbulov authored Jul 10, 2018
commit 77c235e5c150a5d34ea792e79b2434d5d020e941
27 changes: 26 additions & 1 deletion blog/articles/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,32 @@
from django.http import HttpResponse, HttpRequest
import datetime

from django.http import HttpResponse, HttpRequest
from django.views.decorators.http import require_http_methods


def home(request: HttpRequest) -> HttpResponse:
current_time = datetime.date.today().isoformat()
return HttpResponse(current_time, content_type='text/plain')


def handler400(request, *args, **kwargs):
return HttpResponse('Неизвестная операция или деление на ноль', status=400)


@require_http_methods(['GET'])
def calculate(request):
operation = request.GET['op']
left_operand = int(request.GET['left'])
right_operand = int(request.GET['right'])
print(request.GET, operation, left_operand, right_operand)
if operation == '+':
result = left_operand + right_operand
elif operation == '-':
result = left_operand - right_operand
elif operation == '*':
result = left_operand * right_operand
elif operation == '/' and right_operand != 0:
result = left_operand / right_operand
else:
return handler400(request)
return HttpResponse(result)