Django Forms
Learn how to manage forms in Django - For beginners
Last updated
Was this helpful?
Learn how to manage forms in Django - For beginners
Last updated
Was this helpful?
This page explains how to manage and validate a form in Django Framework. We assume the audience has already a Django project up and running. For those that start from nothing, feel free to access the resources mentioned below and come back here once the content is understood:
👉 How to install Django - simple, tested steps to install Django
👉 Django for beginners - a comprehensive tutorial that covers the basics
Topics covered by this tutorial
✅ Create a new Django app
✅ Define a new route
✅ Update the configuration to include the new application
✅ Code a simple form
✅ Integrate the Form into a real page
✅ Update the controller to check the form is validated
The video presentation of this tutorial can be found on Github:
For this, we will use the
startapp
Django subcommand:
Add a simple view in forms -
forms/views.py
Define the routing for our new app -
forms/urls.py
Update settings to include the new app -
config/settings.py
Update routing -
config/urls.py
Once we restart the project, the new route /forms
should be visible:
Inside the newly created app, we need to create a forms
file and define the new Form Class object.
Controller code -
forms/views.py
, theindex()
method
Update App configuration to include the new
Templates
folder,core/settings.py
for AppSeed projects.
HTML page - defined in
forms/templates
folder:
If all fields are provided, on submit, we should see the Form is valid
message.
Update the form with a new field
ID
(numeric type):
The page server to the users is updated automaticaly to include the new field
Thanks for reading! For more topics, feel free to contact Appseed.
Read more about Django (official docs)
Start fast a new project using development-ready Django Starters