Hi! i’m new with Django and I have tried to do calculations with handling requests but just can not figure it out and haven’t really find any help in Internet. I know that this should be pretty easy to do but I have tried to look into it for hours and got nowhere. I would really appreciate the advice if possible. The instructions are as follows:
In this assignment, you will familiarize yourself with handling requests to several paths and request parameters. Implement the following functionality in src/pages/views.py
.
- A request to the path
add/
sums the values in the request GET parametersfirst
andsecond
together and returns the response to the user. Note that the parameters are integers and should also be treated as such. - A request to the path
multiply/
multiplies the values in the request GET parametersfirst
andsecond
and returns the response to the user. Note that the parameters are numbers and should also be treated as such.
For example, add/?first=10&second=10
should result in 20
Views.py is as follows:
from django.http import HttpResponse
Create your views here.
def addPageView(request):
return HttpResponse('0')
def multiplyPageView(request):
return HttpResponse('0')
Urls.py is as follows:
from django.urls import path
from .views import addPageView
from .views import multiplyPageView
urlpatterns = [
path('add/', addPageView, name='add'),
path('multiply/', multiplyPageView, name='multiply')
]