What is Django?
Python-based web framework used for rapid development of web applications.
Installing Django + Setup
Creating a project
The below command creates a new project named projectName
Starting a server
The below command starts the development server.
Django MVT
Django follows MVT(Model, View, Template) architecture.
Sample Django Model
The model represents the schema of the database.
Sample views.py
View decides what data gets delivered to the template.
Sample HTML Template
A sample .html file that contains HTML, CSS and Javascript.
Views in Django
Sample Function-Based Views
A python function that takes a web request and returns a web response.
Sample Class-Based Views
Django's class-based views provide an object-oriented way of organizing your view code.
URLs in Django
Set of URL patterns to be matched against the requested URL.
Sample urls.py file1
Sample urls.py file2
Forms in Django
Similar to HTML forms but are created by Django using the form field.
Sample Django form
Apps in Django
Apps in Django are like independent modules for different functionalities.
Creating an app
Listing app in the settings.py
After creating an app, we need to list the app name in INSTALLED_APPS
Templates in Django
Used to handle dynamic HTML files separately.
Configuring templates in settings.py
Changing the views.py file
A view is associated with every URL. This view is responsible for displaying the content from the template.
Sample template file
Migrations in Django
Migrations are Django's way of updating the database schema according to the changes that you make to your models.
Creating a migration
The below command is used to make migration (create files with information to update database) but no changes are made to the actual database.
Applying the migration
The below command is used to apply the changes to the actual database.
Admin interface in Django
Django comes with a ready-to-use admin interface.
Creating the admin user
Page Redirection
Redirection is used to redirect the user to a specific page of the application on the occurrence of an event.