0
0
Djangoframework~15 mins

Form class definition in Django - Mini Project: Build & Apply

Choose your learning style9 modes available
Form class definition
📖 Scenario: You are building a simple contact form for a website using Django. The form will collect a user's name and email address.
🎯 Goal: Create a Django form class that defines two fields: name and email.
📋 What You'll Learn
Create a Django form class named ContactForm
Add a name field of type CharField with a maximum length of 100
Add an email field of type EmailField
💡 Why This Matters
🌍 Real World
Forms are used on websites to collect user input like contact details or feedback.
💼 Career
Knowing how to create Django form classes is essential for backend web development with Django.
Progress0 / 4 steps
1
Import Django forms module
Write the import statement to import forms from django.
Django
Need a hint?

Use from django import forms to import the forms module.

2
Define ContactForm class
Define a class named ContactForm that inherits from forms.Form.
Django
Need a hint?

Use class ContactForm(forms.Form): to define the form class.

3
Add name field
Inside the ContactForm class, add a name field using forms.CharField with max_length=100.
Django
Need a hint?

Use name = forms.CharField(max_length=100) inside the class.

4
Add email field
Inside the ContactForm class, add an email field using forms.EmailField.
Django
Need a hint?

Use email = forms.EmailField() inside the class.