Froms & Templates Flashcards
1
Q
What are Django Forms?
A
- Simplify the process of handling user input & validating data
- Forms are typically defined as Python classes that sublcass ‘django.forms.Form’ or ‘django.forms.ModelForm’
- Forms can be rendered in templates to collect user input and process it on the server side.
2
Q
How does Django validate Forms?
A
- Django forms include built-in validation to ensure data integrity and force business rules.
- Validation rules are defined using form field attributes and custom validation methods.
- Form validation errors can be displayed in template to provide feedback to users.
3
Q
What occurs when a form is submitted?
A
- Djanto processes the input data and triggers the appropriate view function
- Views handle form submission by validating the input data, performing necessary actions (such as saving to a database), and returning a response.
4
Q
Elaborate on Generic Views
A
- Pre-built view classes provided by Django for common web patterns
- Generic views encapsulate common patterns [e.g CRUD ]
- Developers can write less code and focus on consistent application structure.
5
Q
Class-Based Views
A
CBVs are Python classes that provide reusable components for handling web requests
6
Q
Function-Based View
A
Python functions that process web requests and return responses directly.
7
Q
Generic Views
A
- Import django.views.generic module and subclass it in your views
- Customize generic views by overriding methods or attributes specific to your application’s requirements.
- Generic views provide flexibility through mixins and inheritance, allowing developers to compose views tailored to their needs.