4/10/24, 7:09 PM Django - Jupyter Notebook
DJANGO - PYTHON WEB FRAMEWORK
Framework : It comes with some predefined codes that make our
work easier as it reduces complexity and doesnot need to be
started from scratch.
Web Framework : A web development framework is a set of
resources and tools for software developers to build and manage
web applications, web services and websites, as well as to develop
application programming interfaces (APIs). Web development
frameworks are also referred to as web application frameworks or
simply web frameworks.
As django is a web framework it is used to built web applicatio
n which is now being used everywhere.
So, to build a web application HTML, CSS, JS is being used in f
rontend.
But to handle the backend part we use django.
Django follows MVT structured architecture.
MVT stands for Model View Template where Model is the structure
of data in database, View used to handle the web request, and T
emplates contains static contents like HTML, CSS, JS.
When django project is initialized it contains some basic files
such as [Link], [Link] etc.
Why we need to create a project in django ?
In Django, a project is a top-level container for your web applicat
ion.
A project contains the configurations for your web application and
one or more apps, each providing a specific set of functionalities
or features for your web application.
Steps to start a project:
Step 1: Navigate to your destination folder, open cmd.
localhost:8888/notebooks/Desktop/PYTHON/DSA/[Link]#Working-with-URL. 1/15
4/10/24, 7:09 PM Django - Jupyter Notebook
Step 2: Run this command in the command prompt:
Step 3: Django creates a projectname folder on my computer with the following
python files.
Files inside the project folder.
localhost:8888/notebooks/Desktop/PYTHON/DSA/[Link]#Working-with-URL. 2/15
4/10/24, 7:09 PM Django - Jupyter Notebook
1. __init.py__ - It is a python package invoked when package is im
ported.
2. [Link] - It contains all the website [Link] holds all
the configuration values that your web app needs to work; datab
ase settings, logging configuration, where to find static files
etc .
3. [Link] - It stores all links of project and functions to call.
4. [Link] - It stands for Web Server Gateway Interface. A primary
python standard deployment platform. It is used in deploying th
e project in WSGI. It also helps django application to communic
ate with the webserver.
5. [Link] - It is used to interact with project such as server
start.
Step 4: Open the projectname folder in VSCode.
localhost:8888/notebooks/Desktop/PYTHON/DSA/[Link]#Working-with-URL. 3/15
4/10/24, 7:09 PM Django - Jupyter Notebook
Step 5: Now that you have a Django project, you can run it, and see what it looks like
in a browser.
localhost:8888/notebooks/Desktop/PYTHON/DSA/[Link]#Working-with-URL. 4/15
4/10/24, 7:09 PM Django - Jupyter Notebook
Which will produce this result:
Click on above underlined server
The result:
localhost:8888/notebooks/Desktop/PYTHON/DSA/[Link]#Working-with-URL. 5/15
4/10/24, 7:09 PM Django - Jupyter Notebook
Why we need to create an app in django project ?
The app makes it easy to manage the code of larger projects. An app
helps you organize your codebase by breaking your project's functio
nalities into smaller components.
Steps to start an app:
Step 6: In the terminal, type the underlined command to start an app.
Django creates a folder named appname in my project, with this content:
localhost:8888/notebooks/Desktop/PYTHON/DSA/[Link]#Working-with-URL. 6/15
4/10/24, 7:09 PM Django - Jupyter Notebook
Files inside the app folder
localhost:8888/notebooks/Desktop/PYTHON/DSA/[Link]#Working-with-URL. 7/15
4/10/24, 7:09 PM Django - Jupyter Notebook
1. __init.py__ - The __init__.py file lets the Python interpreter
know that a directory contains code for a Python module. An __i
nit__.py file can be blank. Without one, you cannot import modu
les from another folder into your project.
2. [Link] - The [Link] file is used to display your models in
the Django admin panel. It provides an admin site to allow CRUD
Working with Views.
Django views are Python functions that takes http requests and
returns http response, like HTML documents.
A web page that uses Django is full of views with different tas
ks and missions.
In this views, we need to define our function.
This is way to send a response back to the browser.
But how can we execute the view? Well, we must call the view via a URL.
localhost:8888/notebooks/Desktop/PYTHON/DSA/[Link]#Working-with-URL. 8/15
4/10/24, 7:09 PM Django - Jupyter Notebook
Working with URL.
We need to create a file named [Link] in the same folder as the vi
[Link] file.
After creating a [Link] file in same location as of [Link], we need to include this
app's [Link] to the project's [Link].
Under projectname's [Link], we need to include app's [Link]
localhost:8888/notebooks/Desktop/PYTHON/DSA/[Link]#Working-with-URL. 9/15
4/10/24, 7:09 PM Django - Jupyter Notebook
write the code as follows
Now add the views function to the url for routing.
Inorder to run the server, execute the following code: "python [Link]
runserver"
Click on follow link
localhost:8888/notebooks/Desktop/PYTHON/DSA/[Link]#Working-with-URL. 10/15