0% found this document useful (0 votes)
75 views

Django Setup

Django is a Python web framework that makes it faster and easier to develop web applications. It encourages rapid development and clean, pragmatic design. Django provides various features out of the box like an ORM, admin interface, URL routing, internationalization support, and more. To use Django, one must first install Python, check the Python and pip versions, create a virtual environment to isolate Django projects, install Django within the environment, and then use Django commands to start a new project, migrate models, and run the development server. This allows maintaining different versions of Django for separate projects.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views

Django Setup

Django is a Python web framework that makes it faster and easier to develop web applications. It encourages rapid development and clean, pragmatic design. Django provides various features out of the box like an ORM, admin interface, URL routing, internationalization support, and more. To use Django, one must first install Python, check the Python and pip versions, create a virtual environment to isolate Django projects, install Django within the environment, and then use Django commands to start a new project, migrate models, and run the development server. This allows maintaining different versions of Django for separate projects.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Django

Framework: Django is web application Framework, To build any application we cant do it from
scratch. So we can combine ready made and do Framework.

Basically we use Html, css, javascript to design the pages But these are from Frontend.

We you Django to build web application Backend part in Python.

MVC= Model View Controller

In Django we are having MVT= Model View Template

Why only Django?

1.Fast

2.Components more

3. Security

4. Scalability

Django Setup
Django is A Web Framework for Python.

Django is a web development framework that assists in building and maintaining quality web
applications. Django helps eliminate repetitive tasks making the development process an
easy and time saving experience. This tutorial gives a complete understanding of Django.

Django is a high-level Python web framework that encourages rapid development


and clean, pragmatic design. Django makes it easier to build better web apps
quickly and with less code.
Note − Django is a registered trademark of the Django Software Foundation, and is
licensed under BSD License.
Django – Design Philosophies
Django comes with the following design philosophies −
 Loosely Coupled − Django aims to make each element of its stack
independent of the others.
 Less Coding − Less code so in turn a quick development.
 Don't Repeat Yourself (DRY) − Everything should be developed only in
exactly one place instead of repeating it again and again.
 Fast Development − Django's philosophy is to do all it can to facilitate hyper-
fast development.
 Clean Design − Django strictly maintains a clean design throughout its own
code and makes it easy to follow best web-development practices.

Advantages of Django
Here are few advantages of using Django which can be listed out here −
 Object-Relational Mapping (ORM) Support − Django provides a bridge
between the data model and the database engine, and supports a large set
of database systems including MySQL, Oracle, Postgres, etc. Django also
supports NoSQL database through Django-nonrel fork. For now, the only
NoSQL databases supported are MongoDB and google app engine.
 Multilingual Support − Django supports multilingual websites through its
built-in internationalization system. So you can develop your website, which
would support multiple languages.
 Framework Support − Django has built-in support for Ajax, RSS, Caching
and various other frameworks.
 Administration GUI − Django provides a nice ready-to-use user interface for
administrative activities.
 Development Environment − Django comes with a lightweight web server to
facilitate end-to-end application development and testing.

As you already know, Django is a Python web framework. And like most modern
framework, Django supports the MVC pattern. First let's see what is the Model-
View-Controller (MVC) pattern, and then we will look at Django’s specificity for
the Model-View-Template (MVT) pattern.

MVC Pattern
When talking about applications that provides UI (web or desktop), we usually talk
about MVC architecture. And as the name suggests, MVC pattern is based on three
components: Model, View, and Controller. Check our MVC tutorial here to know
more.

DJANGO MVC - MVT Pattern


The Model-View-Template (MVT) is slightly different from MVC. In fact the main
difference between the two patterns is that Django itself takes care of the Controller
part (Software Code that controls the interactions between the Model and View),
leaving us with the template. The template is a HTML file mixed with Django
Template Language (DTL).
The following diagram illustrates how each of the components of the MVT pattern
interacts with each other to serve a user request −

The developer provides the Model, the view and the template then just maps it to a
URL and Django does the magic to serve it to the user.

Django Setup:
1. Download Python
2.Check Python Version by
C:\Users\sandeep muttineni>python --version
Python 3.7.0

3.Check pip Version


C:\Users\sandeep muttineni>pip --version
pip 21.1.2 from c:\users\sandeep muttineni\appdata\local\programs\python\python37\lib\
site-packages\pip (python 3.7)

4.setting different versions of Django for different projects:


i) By installing Virtual Environment Vapour By- pip install virtualenvwrapper-win

C:\Users\sandeep muttineni>pip install virtualenvwrapper-win


Collecting virtualenvwrapper-win
Using cached virtualenvwrapper-win-1.2.6.tar.gz (21 kB)
Collecting virtualenv
Using cached virtualenv-20.7.2-py2.py3-none-any.whl (5.3 MB)
Collecting platformdirs<3,>=2
Using cached platformdirs-2.2.0-py3-none-any.whl (13 kB)
Collecting importlib-metadata>=0.12
Downloading importlib_metadata-4.6.4-py3-none-any.whl (17 kB)
Collecting distlib<1,>=0.3.1
Using cached distlib-0.3.2-py2.py3-none-any.whl (338 kB)
Collecting filelock<4,>=3.0.0
Using cached filelock-3.0.12-py3-none-any.whl (7.6 kB)
Requirement already satisfied: six<2,>=1.9.0 in c:\users\sandeep muttineni\appdata\local\
programs\python\python37\lib\site-packages (from virtualenv->virtualenvwrapper-win)
(1.16.0)
Collecting backports.entry-points-selectable>=1.0.4
Using cached backports.entry_points_selectable-1.1.0-py2.py3-none-any.whl (6.2 kB)
Collecting zipp>=0.5
Downloading zipp-3.5.0-py3-none-any.whl (5.7 kB)
Collecting typing-extensions>=3.6.4
Using cached typing_extensions-3.10.0.0-py3-none-any.whl (26 kB)
Using legacy 'setup.py install' for virtualenvwrapper-win, since package 'wheel' is not
installed.
Installing collected packages: zipp, typing-extensions, importlib-metadata, platformdirs,
filelock, distlib, backports.entry-points-selectable, virtualenv, virtualenvwrapper-win
Running setup.py install for virtualenvwrapper-win ... done
Successfully installed backports.entry-points-selectable-1.1.0 distlib-0.3.2 filelock-3.0.12
importlib-metadata-4.6.4 platformdirs-2.2.0 typing-extensions-3.10.0.0 virtualenv-20.7.2
virtualenvwrapper-win-1.2.6 zipp-3.5.0

ii) Create environment by= mkvirtualenv test (here test is environment name )

C:\Users\sandeep muttineni>mkvirtualenv test

Create another by naming test1

C:\Users\sandeep muttineni> mkvirtualenv test1


created virtual environment CPython3.7.0.final.0-64 in 1492ms
creator CPython3Windows(dest=C:\Users\sandeep muttineni\Envs\test1, clear=False,
no_vcs_ignore=False, global=False)
seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle,
via=copy, app_data_dir=C:\Users\sandeep muttineni\AppData\Local\pypa\virtualenv)
added seed packages: pip==21.2.3, setuptools==57.4.0, wheel==0.37.0
activators BashActivator,BatchActivator,FishActivator,PowerShellActivator,PythonActivator
iii) now we want to install Django

Here you entered into new environment here we want to install Django.

In test1 enviromment

(test1) C:\Users\sandeep muttineni>pip install django


Collecting django
Using cached Django-3.2.6-py3-none-any.whl (7.9 MB)
Collecting sqlparse>=0.2.2
Using cached sqlparse-0.4.1-py3-none-any.whl (42 kB)
Collecting pytz
Using cached pytz-2021.1-py2.py3-none-any.whl (510 kB)
Collecting asgiref<4,>=3.3.2
Using cached asgiref-3.4.1-py3-none-any.whl (25 kB)
Collecting typing-extensions
Using cached typing_extensions-3.10.0.0-py3-none-any.whl (26 kB)
Installing collected packages: typing-extensions, sqlparse, pytz, asgiref, django
Successfully installed asgiref-3.4.1 django-3.2.6 pytz-2021.1 sqlparse-0.4.1 typing-
extensions-3.10.0.0

iv) check Django version


(test1) C:\Users\sandeep muttineni>django-admin --version
3.2.6

v) to create a folder for our projects= name projets

(test1) C:\Users\sandeep muttineni>mkdir projects

A subdirectory or file projects already exists.

vi) now move to the folder= projects by

(test1) C:\Users\sandeep muttineni>cd projects

(test1) C:\Users\sandeep muttineni\projects>

vii) to use our projects:

(test1) C:\Users\sandeep muttineni\projects>django-admin startproject sunny1

# here sunny1 is name of project

(test1) C:\Users\sandeep muttineni\projects>django-admin startproject sunny1

(test1) C:\Users\sandeep muttineni\projects>

viii) to see what in our project folder


(test1) C:\Users\sandeep muttineni\projects>cd sunny1

(test1) C:\Users\sandeep muttineni\projects>cd sunny1

(test1) C:\Users\sandeep muttineni\projects\sunny1>dir


Volume in drive C is OS
Volume Serial Number is 9AD5-C957

Directory of C:\Users\sandeep muttineni\projects\sunny1

21-08-2021 09:06 <DIR> .


21-08-2021 09:06 <DIR> ..
21-08-2021 09:06 684 manage.py
21-08-2021 09:06 <DIR> sunny1
1 File(s) 684 bytes
3 Dir(s) 267,280,666,624 bytes free

(test1) C:\Users\sandeep muttineni\projects\sunny1>

ix) to work with this file we want to run server


by

(test1) C:\Users\sandeep muttineni\projects\sunny1>python manage.py runserver

Watching for file changes with StatReloader


Performing system checks...

System check identified no issues (0 silenced).

You have 18 unapplied migration(s). Your project may not work properly until you apply the
migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
August 21, 2021 - 09:49:25
Django version 3.2.6, using settings 'sunny1.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.

V are ready Now

There are two Types of Webpages


1.Static Pages = commen for everyone
2.Dynamic Pages= Separate for every individual like facebook, insta, utube
To build app open all in visual studio and open the file of PROJECT we created
Then open terminal and do all cooding

We created a separate environment so we have to open it and Do all our stuff


Note: while opening open Developer Command Prompt in Terminal
And we are working on test1 evironment open that using following

C:\Users\sandeep muttineni\projects\sunny1>workon test1


(test1) C:\Users\sandeep muttineni\projects\sunny1>python manage.py startapp sun

(test1) C:\Users\sandeep muttineni\projects\sunny1>

Here sun is name of the app

To do any thing on that app for anu modifications


We want to open new urls.py in our app folder
Ex=sun
By clicking on sun and add new file urls.py

Then after copy the url from sunny1 file


2nd url that is
From Django.urls import path
from django.urls import path

check 4th video very well to all


ever time open
workon test1 environment and work to complete the
work

You might also like