How to extract data from an html form using django?

Programming Hints

I have html form with some text input for a users registration, the form is like this:

<form id="signup-form" action="#" method="post">
                 <label for="name">Full Name</label>
                 <input autocomplete="off" type="text" name="username" id="name" class="name">

                 <label for="email">Email Adderss</label>
                 <input autocomplete="off" type="email" name="emailAdress" id="email" class="email">
                 
                 <label for="phone">Phone Number - <small>Optional</small></label>
                 <input autocomplete="off" type="text" name="phone" id="phone">

            
                 <label for="password">Password</label>
                 <input autocomplete="off" type="password" name="password" id="password" class="pass">
              
                 <label for="passwordCon">Confirm Password</label>
                 <input type="password" name="passwordCon" id="passwordCon" class="passConfirm">
                 <input type="submit" form="signup-form" value="Signup Now" id="submit">
           </form>

I want to know, how can i store the values of each input, when the button is submitted and save them in the database, is there a way to call the input field by its ID and store it in Django?

Om Kashyap

Your code template is missing a lot of things like urls , views and models . What views you are working with , url of the form submission , and what database. But here is a simple structure of the form submission if you are using django user model and not using custom model .

You have your form template. It works fine , but add a new field after tag for csrf_verification of the template.

<form>
{% csrf_token %}
...

...
</form>

Your urls.py for the signup

from django.urls import path
from . import views

urlpatterns = [
    path("signup/" , views.signUpView , name = "user-signup") , 
]

Your views.py I am using a function-based view here and django User model.

from django.contrib.auth.models import User
from django.contrib.auth import login

def signUpView(request , *args , **kwargs):
    if request.method == "POST":
        username = request.POST.get("username")
        emailAddress = request.POST.get("emailAddress")
        password = request.POST.get("password")
        
        # get all your fields which you gave in the form.

        user = User(userrname = username , email = emailAddress )
        user.set_password(password)
        user.save()
        login(request , user)
        return redirect("homepage")
    else :
        return render(request , "signupPage.html")

This is your basic template and working of django signup page. And this will do your work which you are asking for. For detailed and specific answer. Elaborate the question.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to pass data from html template (using html form) to views.py python in django?

in django how to add data from html table without using form.py

How to store data from html form to postgres database using Django 1.10?

how to extract data from html table using jQuery each function

How to extract data from HTML using beuatiful soup

how can extract special data from html using jsoup in android

How to keep html form data after submission using django?

How to save form data from base.html in django?

How to send json serialize data from a form to ajax using django

how to send form data from one page to another using django

Django : How to import a data from csv to database without using form?

How to send data from HTML form to Google Spreadsheet using JavaScript?

How to get data from html form using Google App Script

Extract data from html using python,

Extract data from html to csv using BeautifulSoup

Django retrieve data from html form

Access data from html form in Django

In Django, how to extract ID attribute from html Input tag, WITHOUT using django forms

how to extract zip data from response in django

How to extract Data from Django Queryset

How to pre-populate form with data received from a previous HTML form submission in Django?

How to extract data from the following html?

How to extract data from HTML divs into Excel

How to extract Django Form errors message without the HTML tags

How to Edit Data in Django dropdown HTML form?

How to extract text from html using XPATH

How to extract HTML from a database using Linq?

how to extract text from html using beautifulsoup?

How to extract links from HTML using BeautifulSoup?