Sanjay Rathore presents an introduction to the Django web framework. He discusses key features of Django including rapid development, security, and scalability. He outlines the MVT (Model View Template) architecture, describing the roles of each component. He also demonstrates how to install Django, set up a virtual environment, and build a basic MVT application with URL routing and templates. Pros of Django include its Python-based code, database management, and security, while cons are its potential heaviness for small projects.
Presented By: SanjayRathore (Software Consultant) Introduction to Django Framework
2.
Lack of etiquetteand manners is a huge turn off. KnolX Etiquettes Punctuality Respect Knolx session timings, you are requested not to join sessions after a 5 minutes threshold post the session start time. Feedback Make sure to submit a constructive feedback for all sessions as it is very helpful for the presenter. Silent Mode Keep your mobile devices in silent mode, feel free to move out of session in case you need to attend an urgent call. Avoid Disturbance Avoid unwanted chit chat during the session.
Introduction ● Django isa high-level Python framework. It is free and open-source, written in Python itself, and follows the model-view-template architectural pattern. ● We can use it to develop quality web applications faster and easier. Since developing for the web needs a set of similar components, you can use a framework. ● This way, you don’t have to reinvent the wheel. These tasks include authentication, forms, uploading files, management panels, and so. LEARN NOW
5.
c Features 1. Rapid Development 2.Secure 3. Scalable 4. Fully loaded 5. Versatile 6. Open Source 7. Vast and Supported Community LEARN NOW
6.
OUR MISSION ● TheModel is the part of the web-app which acts as a mediator between the website interface and the database. In technical terms, it is the object which implements the logic for the application’s data domain. ● View is actually the User Interface of the web-application and contains the parts like HTML, CSS and other frontend technologies. Generally, this UI creates from the Models component, i.e., the content comes from the Models component. ● The controller as the name suggests is the main control component. It means,the controller handles the user interaction and selects a view according to the model. ● The main task of the controller is to select a view component according to the user interaction and also applying the model component. Project Architecture
7.
Installation Process Steps toInstall Django and Set Up a Virtual Environment 1. Install Python3 $ sudo apt-get install python3 2. Install pip $ sudo apt-get install -y python3 pip 3. create virtual environment $ pip3 install virtualenv 4. Installing Django $ pip install -e django
8.
c MVT Architecture Model logical DS Template presentation layer View data formatting design, update,delete data inputby user data to display Models :- Just like the Model in MVC, here as well it has the same functionality of providing the interface for the data stored in the database. Views :-In Django, Views act as a link between the Model data and the Templates. It sees the user request, retrieves appropriate data from the database, then renders back the template along with retrieved data. Templates:- Just like View in MVC, Django uses templates in its framework. Templates are responsible for the entire User Interface completely. It handles all the static parts of the webpage along with the HTML, which the users visiting the webpage will perceive.
9.
Control Flow 1. Theuser sends a URL request for a resource to Django. 2. Django framework then searches for the URL resource. 3. If the URL path links up to a View, then that particular View is called. 4. The View will then interact with the Model and retrieve the appropriate data from the database. 5. The View then renders back an appropriate template along with the retrieved data to the user.
10.
App Life Cycle Createan Application We assume you are in your project folder. In our main “myproject” folder, the same folder then manage.py − $ python manage.py startapp myapp myapp/ __init__.py admin.py models.py tests.py views.py $ django-admin startapp projectApp or
11.
Admin Interface Django providesa ready-to-use user interface for administrative activities. ● We need some modules are imported in the INSTALLED_APPS and MIDDLEWARE_CLASSES tuples of the myproject/settings.py file. Create SuperUser for the Admin access python manage.py createsuperuser from django.conf.urls import patterns, include, url from django.contrib import admin admin.autodiscover() urlpatterns = patterns('', url(r'^admin/', include(admin.site.urls)),) Now run the server - $ python manage.py runserver
12.
www.website.com URL Routing Since Djangois a web application framework, it gets user requests by URL locater and responds back. To handle URL, django.urls module is used by the framework. Let's open the file urls.py of the project and see the what it looks like: //urls.py Django already has mentioned a URL here for the admin. The path function takes the first argument as a route of string or regex type. from django.contrib import admin from django.urls import path urlpatterns = [ path('admin/', admin.site.urls), ]
13.
www.website.com Django Temple Language(DTL) Django’stemplate engine offers a mini-language to define the user-facing layer of the application. A variable looks like this: - {{variable}}. hello.html <html> <body> Hello World!!! <p>Today is {{today}}</p> </body> </html> views.py <html> <body> Hello World!!!<p>Today is {{today}}</p> </body> </html> def hello(request): today = datetime.datetime.now().date() return render(request, "hello.html", {"today" : today})
www.website.com Pros : ● Pythonis vastly more writable than other language; ● Excellent for big projects; ● Magical ORM; ● Easy database management; ● Security. cons: ● Not the best for small projects; ● Heavy and you probably won’t utilize the whole framework; ● Monolithic one; ● All components get deployed together.