0% found this document useful (0 votes)
6 views11 pages

PPP Django

The presentation covers Django's template systems, models, and forms, explaining how templates render dynamic content, models define database structure, and forms facilitate user input handling. Key features include the use of variables, tags, and filters in templates, as well as basic operations for models and form validation. The document concludes by summarizing the importance of these components in Django development.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views11 pages

PPP Django

The presentation covers Django's template systems, models, and forms, explaining how templates render dynamic content, models define database structure, and forms facilitate user input handling. Key features include the use of variables, tags, and filters in templates, as well as basic operations for models and form validation. The document concludes by summarizing the importance of these components in Django development.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Presentation Title : Template Systems, Models, and Form Details

Presentation Date: 09-April-2025

Presented By:- Presented To:-


Mohammad Kashif Mr. Gaurav Dwivedi Sir
Fahad Naved Jafri
B.Tech (Core)
6th Semester
Index
1. Template Systems in Django

2. Django Models

3. Forms in Django

4. Example: Building a User Registration Form

5. Conclusion

6. Q&A*
Template Systems in Django

What is a Template in Django?


A template in Django is an HTML file that allows for dynamic content rendering by
embedding placeholders for variables and logic.

Template Engine:
Django comes with its own template engine, but it also supports integration with other
template engines like Jinja2.
:

Key Features of Django Template System

Variables: Placeholders that represent dynamic content (e.g., {{ user.name }}).


In Django templates, you can render variables by putting them inside {{ }} brackets

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

Filters: Used to modify variables' output (e.g., {{ date|date:"Y-m-d" }}).


1. date – Formatting Dates
2. length – Length of a List/String
Django Models

What is a Model in Django?

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.

Features of Django Models: -


Fields: Define attributes of your data (e.g., CharField, EmailField).
Methods: Custom behavior and actions on your data. -
Migration: Django uses migrations to handle changes to your models and sync them with the
database.

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

Models are defined in models.py within a Django app.


Example:
python
class User(models.Model):
username = models.CharField(max_length=100)
email = models.EmailField()
password = models.CharField(max_length=100)
Forms in Django

What is a Form in Django?


Django forms allow for the creation, validation, and processing of user input data.

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

Forms are defined in forms.py within a Django app.


Example:
python
from django import forms
class UserRegistrationForm(forms.Form):
username = forms.CharField(max_length=100)
email = forms.EmailField()
password = forms.CharField(widget=forms.PasswordInput)
Conclusion

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.

You might also like