ppp django
ppp django
2. Django Models
3. Forms in Django
5. Conclusion
6. Q&A*
Template Systems in Django
Template Engine:
Django comes with its own template engine, but it also supports integration with other
template engines like Jinja2.
:
Tags: Control structures like loops and conditionals (e.g., {% for user in users %}).
1. {% for %} – Looping through a list
2.{% if %} – Conditional Statement
3. {% url %} – URL Reversal
A model is a Python class that defines the structure of your database. It defines the fields and
behaviors of the data you want to store.
Basic Operations:
Create: User.objects.create(username='john', email='[email protected]') -
Read: User.objects.all(), User.objects.filter() -
Update: user_instance.username = 'new_name’
Delete: user_instance.delete()
Creating a Model
Form Handling:
Forms are crucial for collecting data from users and saving it to models or processing it.
Form Validation:
Field Validators: Custom validation rules for form fields (e.g., check if email is unique). -
Cleaning Data: cleaned_data contains valid data after form submission.
Creating a Form
Template Systems: In Django, templates render dynamic content by embedding Python variables
and logic into HTML.
Models: Django models define the structure of the database and provide easy-to-use query
methods through the Django ORM.
Forms: Django forms allow for easy handling of user input, validation, and interaction with
models.
If Any Doubt ?
Ask Question