Django:get field values using views.py from html form

Each input should have a name attribute:

<input type="text" name="username" class="form-control"
                                      placeholder="Desired Username" />

And then in your view you can access that data using request.POST or request.GET dictionary-like objects (it depends on the method attribute of the <form> tag):

def register(request):
    username = request.POST['username']
    ...

But you shouldn't render/handle forms this PHPish way. Learn the django forms.


To catch the data in python backend

for POST request:

def register(request):
    username = request.POST.get('username')

for GET request

def register(request):
    username = request.GET.get('username')

.get was missing on earlier answer

Tags:

Forms

Django