
Quick Contact
Python Tutorial
- What is Python?
- How to Install Python?
- Python Variables and Operators
- Python Loops
- Python Functions
- Python Files
- Python Errors and Exceptions
- Python Packages
- Python Classes and Objects
- Python Strings
- PostgreSQL Data Types
- Python Generators and Decorators
- Python Dictionary
- Python Date and Time
- Python List and Tuples
- Python Multithreading and Synchronization
- Python Modules
- What is Python bytecode?
- Python Regular Expressions
Python Panda Tutorial
- Python Pandas Tutorial
- Python Pandas Features
- Advantages and Disadvantages of Python Pandas
- Pandas Library In Python
- Pandas Series To Frame
- Python Dataframeaggregate and Assign
- Pandas Dataframe Describe
- Pandas Dataframe Mean
- Pandas Hist
- Pandas Dataframe Sum
- How to convert Pandas DataFrame to Numpy array
Python Selenium
- Selenium Basics
- Selenium with Python Introduction and Installation
- Navigating links using get method Selenium Python
- Locating Single Elements in Selenium Python
- Locating Multiple elements in Selenium Python
Python Flask Tutorial
Python Django
- How to Install Django and Set Up a Virtual Environment in 6 Steps
- Django MTV Architecture
- Django Models
- Django Views
- Django Templates
- Django Template Language
- Django Project Layout
- Django Admin Interface
- Django Database
- Django URLs and URLConf
- Django Redirects
- Django Cookies and Cookies Handling
- Django Caching
- Types of Caching in Django
- Django Sessions
- Django Forms Handling & Validation
- Django Exceptions & Error-handling
- Django Forms Validation
- Django Redirects
- Django Admin Interface
- Django Bootstrap
- Ajax in Django
- Django Migrations and Database Connectivity
- Django Web Hosting and IDE
- Django Admin Customization
- What is CRUD?
- Django ORM
- Django Request-Response Cycle
- Django ORM
- Making a basic_api with DRF
- Django Logging
- Django Applications
- Difference between Flask vs Django
- Difference between Django vs PHP
Numpy
- Numpy Introduction
- NumPy– Environment Setup
- NumPy - Data Types
- NumPy–Functions
- NumPy Histogram
- numPy.where
- numpy.sort
- NumPyfloor
- Matrix in NumPy
- NumPy Arrays
- NumPy Array Functions
- Matrix Multiplication in NumPy
- NumPy Matrix Transpose
- NumPy Array Append
- NumPy empty array
- NumPy Linear Algebra
- numpy.diff()
- numpy.unique()
- numpy.dot()
- numpy.mean()
- Numpy.argsort()
- numpy.pad()
- NumPyvstack
- NumPy sum
- NumPy Normal Distribution
- NumPylogspace()
- NumPy correlation
- Why we learn and use Numpy?
Tensorflow
- Introduction To Tensorflow
- INTRODUCTION TO DEEP LEARNING
- EXPLAIN NEURAL NETWORK?
- CONVOLUTIONAL AND RECURRENT NEURAL NETWORK
- INTRODUCTION TO TENSORFLOW
- INSTALLATION OF TENSORFLOW
- TENSORBOARD VISUALIZATION
- Linear regression in tensorflow
- Word Embedding
- Difference between CNN And RNN
- Explain Keras
- Program elements in tensorflow
- Recurrent Neural Network
- Tensorflow Object Detection
- EXPLAIN MULTILAYER PERCEPTRON
- GRADIENT DESCENT OPTIMIZATION
Interview Questions & Answers
Django Forms Handling & Validation
Nowadays websites have become highly personalized resulting to some awesome applications for users. This personalization is an impact of user-data on the server. And, that data is highly valuable for you as it is used to provide a better user experience and more functionality. But, it also has some serious security consequences and legal issues. Therefore, when designing any user-input, keep in mind that user-data is highly valuable.
So the question that should arise in your mind, how do we take user input and utilize the same? The answer is simple through forms.
After completing this Django forms tutorial, you will have a great command over these concepts:
- Forms
- HTTP, GET & POST Method
- Django Forms
- Django Form Class
- Django Form Validation
What are Forms?
Forms are a collection of HTML elements to take input from the user. In simple words, whenever you give any kind of instruction or input on web, that is known as a form.
The input elements come inside < form>< /form> tags. It is collectively called as HTML form. All the websites use forms each having different use-cases.
Some daily examples of forms can include:
- Google search
- Facebook posts and stories
- Online registrations
- Online Quizzes, tests, etc
There are too many examples. Forms have become an essential part of web applications.
We use them to structure and transmit user-data over HTTP. They provide all kinds of input options to be taken from the user.
What is HTTP?
HTTP is an acronym for HyperText Transfer Protocol. It is the set of rules which all the computers on a network follow to transmit data to other computers. All client/server architectures are based on this protocol.
There are different methods to transmit data over HTTP. The 2 very popular methods among all of them are GET and POST.
-
GET
We use this method for user-data which will not be changing the state of the website. GET is a method of transmitting form data via URL.
Google search is the best example of the same. We use this method for transmitting data which doesn’t make changes in the database.
GET method comes in handy when we want to bookmark pages as our search query becomes part of the URL.
GET method is often limited by the size of the URL. Anything more than URL size cannot be transmitted. That means we can only send text requests.
-
POST
This method is used for sensitive data and it changes the state of the website. POST is a method of transmitting data as collective structure over HTTP. It is sent as a different request from client alongside URL request, like cookies.
POST data is not a cookie, it is just a different type of resource. This method is more secure than getting because the data is not in URL. The POST method also has a greater size limit, allowing for file uploads.
This method is used on all the registration forms and quizzes.
HTML Forms
The < form> tag has two important attributes to be specified:
-
Action
This attribute specifies where to submit the form data. It can be left blank but in that case, the data will be sent to the same URL. Otherwise, you can specify a URL. This attribute just tells the form where to submit the data.
-
Method
This attribute specifies how to submit data. There are GET and POST values for the same. You should use capital values for this attribute.
They will function as explained in the previous section.
Django Forms Handling
First, we have to understand how the server responds with forms and where do the forms fit in all the client/ server architecture?
When a form is rendered in Django, these steps are involved:
-
-
Render the Form in its Initial State
When client requests form for the first time, the server responds with an empty form. The form fields can have initial values and help texts at that point. The initial state can consist data which may or may not be changed by the user.
-
Receive the Form Data & Validate the Information
When the users has a completely filled form, they submit it. The data received by the server needs to be validated.
Here, validation means all kinds of things. Like,
- If it is a valid email or not.
- The passwords match with re-entered passwords or not.
-
There are 2 different types of validations:
-
-
- Custom validations
- Built-in validations
-
Their use depends on developer and project requirements.
-
If the Received Data is not Valid, Response is a Bounded Form
When you validate the form data, the function will either result in true or false. That means user either entered valid data or invalid data. In the latter case, we will have the server to return the form again, but this time form is bounded.
A bounded form has user data in form fields. For example – when you sign-in on the website, at the time wrong password submission, the page does not reset your whole information rather it returns all the values in corresponding fields, filled by you and highlights only those fields where data is invalid.
That response is a bounded form.
-
If the Received Data is Valid, a Success Response will generate
When your form data is validated, then response is a redirect or any success page. This part is also different for different websites.
When the client/ browser requests for form for the first time, we receive a GET request, that’s how we check whether a request has been made for the first time. Then, the server responds with a default form, with initial values.
In the second phase, the user completes and submits the form. This time the sumission was via the POST method. It will make the server recognize this request and perform validation checks.
After that, you have to validate the form data . If the data is valid, we provide some kind of success response to our user. Otherwise, we respond with a bounded form stating that something was wrong in data, highlighting that particular field of data.
Again, this process is repeated until the data becomes validated.
Django Form Class
Forms are implemented via Django form class. Some built-in tasks which Django provides you are:
- Rendering Form
- Form Validation
And there are many more but we will be covering these 2 in our tutorial as these are the major ones.
Django form class is very similar to the Django models class. Django form class provides you lots of functionality with forms and their validations. This class has many built-in forms which you can use directly to render HTML. You can also define forms, just like models and render the same.
Apply now for Advanced Python Training Course