0% found this document useful (0 votes)
118 views54 pages

Django

Django is a Python-based web framework that allows for quick creation of web applications without installation or dependency issues. It provides ready-made components for common needs like user authentication, admin panels, and file uploads. Key advantages of Django include ease of database switching, a built-in admin interface, being a fully functional framework, availability of thousands of additional packages, and scalability. Django can build many types of websites and works with various front-end frameworks and data formats. It is designed with security in mind and scales horizontally. Code is portable across platforms as Django is written in Python.

Uploaded by

Atchayha P M
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
118 views54 pages

Django

Django is a Python-based web framework that allows for quick creation of web applications without installation or dependency issues. It provides ready-made components for common needs like user authentication, admin panels, and file uploads. Key advantages of Django include ease of database switching, a built-in admin interface, being a fully functional framework, availability of thousands of additional packages, and scalability. Django can build many types of websites and works with various front-end frameworks and data formats. It is designed with security in mind and scales horizontally. Code is portable across platforms as Django is written in Python.

Uploaded by

Atchayha P M
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 54

Django

Presented By:
Dhanya G
Introduction
• Django is a Python-based web framework which allows you to quickly
create web application without all of the installation or dependency
problems that you normally will find with other frameworks.

• When you’re building a website, you always need a similar set of


components: a way to handle user authentication (signing up, signing
in, signing out), a management panel for your website, forms, a way to
upload files, etc. Django gives you ready-made components to use.
Why Django?

1.It’s very easy to switch database in Django framework.


2.It has built-in admin interface which makes easy to work with it.
3.Django is fully functional framework that requires nothing else.
4.It has thousands of additional packages available.
5.It is very scalable.
Features of Django

• Versatility of Django
Django can build almost any type of website. It can also work with
any client-side framework and can deliver content in any format such
as HTML, JSON, XML etc. Some sites which can be built using
Django are wikis, social networks, new sites etc.
• Security
Since Django framework is made for making web development easy, it
has been engineered in such a way that it automatically do the right
things to protect the website
Features of Django

• Scalability
Django web nodes have no stored state, they scale horizontally – just
fire up more of them when you need them. Being able to do this is the
essence of good scalability. Instagram and Disqus are two Django
based products that have millions of active users, this is taken as an
example of the scalability of Django.
• Portability
All the codes of the Django framework are written in Python, which
runs on many platforms. Which leads to run Django too in many
platforms such as Linux, Windows and Mac OS.
Installation of Django
• Open command prompt - python -m pip install -U pip
Install virtual environment- 

• Enter following command in cmd- pip install virtualenv


Set Virtual environment- 
• Setting up the virtual environment will allow you to edit the
dependency which generally your system wouldn’t allow.

• Create a virtual environment by giving this command in cmd-


• virtualenv env_site
continue
Install Django- Install django by giving
following command-
• Pip install Django
Downloading
Creating new project
• Return to the env_site directory-
cd ..
Create the project by :
django-admin startproject first_try
Change directory to first_try
• cd first_try
Start the server- Start the server by typing
following command in cmd-
• python manage.py runserever
Check
• To check whether server is running or not go to web browser and
enter http://127.0.0.1:8000/ as url.
C:\Users\DELL\env_site\first_try\first_try
• _init_.py – It is a python package. It is invoked when the package or a
module in the package is imported. We usually use this to execute package
initialization code, for example for the initialization of package-level data.
• settings.py – As the name indicates it contains all the website settings. In
this file, we register any applications we create, the location of our static
files, database configuration details, etc.
• urls.py – In this file, we store all links of the project and functions to call.
• wsgi.py – This file is used in deploying the project in WSGI. It is used to
help your Django application communicate with the webserver.
• Create a new file views.py inside the project folder where settings.py,
urls.py and other files are stored and save the following code in it- 

from django.http import HttpResponse


def hello_program (request) :
return HttpResponse("Hello Geeks")
Open urls.py inside project folder
(projectName) and add your entry-
• Import hello_program function from views.py file. 

• from projectName.views import hello_program



Add an entry in url field inside url patterns- 

path(‘first/', hello_program),
Run
Change directory
• cd first_try

Start the server- Start the server by typing following command in


cmd- 
$ python manage.py runserver

Checking – Open the browser and type this url- 


http://127.0.0.1:8000/first/
Output
Add 2 numbers
Run the program
Command Prompt
Output
Creating form and adding
• Create a project from command prompt

• django-admin startproject add


• cd add
• Now open the file
Code
• Create a folder template inside the project.

• Inside the folder template create a file


• form.html
form.html
Explanation
• This form is having 2 textbox
num1 and num2
There is a button – submit

And it is inside a form tag

Action = add (this will take you to urls.py when button is clicked)
Continue
• Form.html

• File will be loaded when it is called, and it is kept inside the function
• In views.py file
Views.py
Urls.py
Change in settings.py
Run the program now
• Python manage.py runserver
Next to add them
• Give action=“add” in form (form.html)
• When button is clicked (in urls.py)
Function add inside views.py
• name = “add” ( function name in views.py)
• Write the function is views.py
Explanation
• To get the value given in the textbox use:
• GET method
num1 = request.GET['num1']
num2 = request.GET['num2']
s = int(num1) + int(num2)
GET[‘num1’] -> (name of the textbox) and save it into the variable
num1
GET[‘num2’] -> (name of the textbox) and save it into the variable
num2
result.html
Explanation
• The result is displayed (one which is given inside curly brackets)
output
Calculator program using method = post
• Template -> calc.html
Urls.py
Views.py
Django forms
• Create forms.py
Urls.py
settings
Views.py
Create a folder template inside project
• Add .html files inside that (home.html)
Path
Database connection
• https://www.geeksforgeeks.org/how-to-install-mysql-in-windows/

• Install mysql
Create a project
• https://pythonguides.com/python-django-mysql-crud/

• django-admin startproject Blog

• (The project which is created here is Blog)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy