Django
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.
• 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-
path(‘first/', hello_program),
Run
Change directory
• cd first_try
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/