Last modified: Jan 11, 2023 By Alexander Williams

request post example in django

lets start by create a form.

First, create a file inside the directory of your blog application and make it look like this:
from django import forms
class login_Form(forms.Form):
    username = forms.CharField(max_length=25)
    password = forms.CharField(widget=forms.PasswordInput)
from .forms import *
def login(request):
    form = login_Form()
    # Handling forms
    if request.method == "POST":
        form = login_Form(request.POST)
        if form.is_valid():
            return HttpResponse('The form has been sent')
           form = login_Form()  
    return render(request, 'login.html', {'form':form})
path('login', login, name='form_login'),


<!DOCTYPE html>
<form action="{% url 'form_login' %}" method="POST">
{% csrf_token %}
<input type="submit" name="submit" value="POST">

after submitting the form, we'll get this message

The form has been sent