Django form request is always response with "GET" instead of "POST" even when I use <form action="" method="post">

Please help me m looking since hours for the solution but i didnt find something.

Here is my HTML:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.3.1/dist/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">

    <style>
        input {
            width: 10%;
            margin: 0 auto;
            display: block;
            margin-left: auto;
            margin-right: auto;
        }
    </style>

</head>

<body>


    {% load crispy_forms_tags %}

    <div class="container">
        <form action="" method="post">

        {% csrf_token %}
            {% crispy form %}
        <input type="submit" class="btn btn-primary mx-auto d-block">
        </form>
    </div>


</body>
</html>

and here is my views.py:


from django.shortcuts import render
from .forms import UserInformationForm
# Create your views here.


def register(request):
    form = UserInformationForm()
    context = {"form": form}

    print(form)

    if request.method == "POST":
        print("Post")
        form = UserInformationForm(request.POST)
        if form.is_valid():
            form.save()
            print(form)

    return render(request, 'index.html', context)

The only response i get is: "GET /register/ HTTP/1.1" 200 3542

I already tried things like if request.method == "GET": But then I had on every field in my form a mark with "This fiel is required"

hello please check django documentation enter link description here

    form = UserInformationForm()
    context = {"form": form}

you dont have to add these codes.if this is a POST request we need to process the form data

Back to Top