Формы POST запрос
Содержимое файла urls.py
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^my_page_with_form/', views.my_page_with_form, name='my_page_with_form'),
url(r'^my_page_with_answer/', views.my_page_with_answer, name='my_page_with_answer'),
url(r'^count_summa_of_numbers/', views.count_summa_of_numbers, name='count_summa_of_numbers')
]Содержание файла views.py
from django.shortcuts import render
from django.http import HttpResponse
from django.http import HttpResponseRedirect
def my_page_with_form(request):
return render(request, 'prilogenie111/my_page_with_form.html', {})
def my_page_with_answer(request):
return render(request, 'prilogenie111/my_page_with_answer.html', {})
def count_summa_of_numbers(request):
a = str( request.POST['a'] )
b = str( request.POST['b'] )
summa = float(a) + float(b)
print("Find Summa:")
print(a)
print(b)
print(summa)
return HttpResponseRedirect("/my_page_with_answer/" + str(summa))Содержание HTML страницы с формой ввода чисел
Содержание HTML страницы, на которой выводится результат вычислений
Last updated
Was this helpful?