0% found this document useful (0 votes)
2 views8 pages

Django Forms

The document explains the concept of forms in HTML, detailing their structure and the importance of specifying the URL and HTTP method for data submission. It distinguishes between the GET and POST methods, highlighting their specific use cases in web applications, particularly in Django. Additionally, it outlines Django's role in simplifying form handling, including data preparation, HTML form creation, and processing submitted data.

Uploaded by

arunasekaran
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views8 pages

Django Forms

The document explains the concept of forms in HTML, detailing their structure and the importance of specifying the URL and HTTP method for data submission. It distinguishes between the GET and POST methods, highlighting their specific use cases in web applications, particularly in Django. Additionally, it outlines Django's role in simplifying form handling, including data preparation, HTML form creation, and processing submitted data.

Uploaded by

arunasekaran
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Django Forms

Subtitle
What is a form?
• In HTML, a form is a collection of elements inside
<form>...</form> that allow a visitor to do things like enter text,
select options, manipulate objects or controls, and so on, and
then send that information back to the server.

• Some of these form interface elements - text input or


checkboxes - are built into HTML itself. Others are much more
complex; an interface that pops up a date picker or allows you to
move a slider or manipulate controls will typically use JavaScript
and CSS as well as HTML form <input> elements to achieve these
effects.
What is a form?
• As well as its <input> elements, a form must specify two things:

where: the URL to which the data corresponding to the user’s


input should be returned
how: the HTTP method the data should be returned by
GET and POST
• GET and POST are the only HTTP methods to use when dealing with forms.

• Django’s login form is returned using the POST method, in which the
browser bundles up the form data, encodes it for transmission, sends it to
the server, and then receives back its response.

• GET, by contrast, bundles the submitted data into a string, and uses this to
compose a URL. The URL contains the address where the data must be
sent, as well as the data keys and values. You can see this in action if you
do a search in the Django documentation, which will produce a URL of the
form https://docs.djangoproject.com/search/?q=forms&release=1.
GET and POST
• GET and POST are typically used for different purposes.

• Any request that could be used to change the state of the system
- for example, a request that makes changes in the database -
should use POST. GET should be used only for requests that do
not affect the state of the system.
Django’s role in forms
• Handling forms is a complex business. Consider Django’s admin, where numerous items of data
of several different types may need to be prepared for display in a form, rendered as HTML,
edited using a convenient interface, returned to the server, validated and cleaned up, and then
saved or passed on for further processing.

• Django’s form functionality can simplify and automate vast portions of this work, and can also do
it more securely than most programmers would be able to do in code they wrote themselves.

• Django handles three distinct parts of the work involved in forms:

• preparing and restructuring data to make it ready for rendering


• creating HTML forms for the data
• receiving and processing submitted forms and data from the client
• It is possible to write code that does all of this manually, but Django can take care of it all for you.
Forms in Django
• We’ve described HTML forms briefly, but an HTML <form> is just
one part of the machinery required.

• In the context of a web application, ‘form’ might refer to that


HTML <form>, or to the Django Form that produces it, or to the
structured data returned when it is submitted, or to the end-to-
end working collection of these parts.
Django Model Field Type
• • CharacterField • • ImageField
• • IntergerField • • FileField
• • FloatField • • EmailField
• • DecimalField • • URLField
• • DateField • • ForeignKey
• • TimeField • • OneToOneField
• • DateTimeField • • ManyToManyField
• • TextField • • PositiveIntegerField
• • BooleanField

You might also like