> For the complete documentation index, see [llms.txt](https://maxim218.gitbook.io/django/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://maxim218.gitbook.io/django/formi-post-zapros.md).

# Формы POST запрос

Содержимое файла **urls.py**

```python
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**

```python
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 страницы с формой ввода чисел

```
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Form Page</title>
</head>
<body>

<h1>Form Page</h1>
<hr>

<form action = "/count_summa_of_numbers/" method = "POST">
    {% csrf_token %}
    A <input type = "text" name = 'a'>
    <br>
    <br>
    B <input type = "text" name = 'b'>
    <br>
    <br>
    <input type = "submit" value = "Получить сумму">
</form>

</body>
</html>
```

Содержание HTML страницы, на которой выводится результат вычислений

```
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Answer Page</title>
</head>
<body>

<h1>Answer Page</h1>
<hr>

<h3 id = "myContent"></h3>

<a href = "/my_page_with_form/">Вернуться</a>

<script>
    "use strict";

    window.onload = function() {
        const myContent = document.getElementById("myContent");
        const mass = (window.location + "").split("/");
        const answer = mass[mass.length - 1].toString();
        myContent.innerHTML = answer;
    }
</script>

</body>
</html>
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://maxim218.gitbook.io/django/formi-post-zapros.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
