Вы находитесь на странице: 1из 10

Chapter-9

Creating a Django based Basic Web Application

Introduction :Django is a web framework that is used along with Python


to develop dynamic websites.

Web Framework – A Web Framework is a software tool that provides a


way to build and run dynamic websites and web-enabled applications.

How Web, Websites and Web-application Work ?

Web works in the form of client-server architecture. Our web


browser act as a client program (web client or the front-end), and
the web server with which it interact is the server (the backend).

The client (web browser) work on the web mostly with HTTP protocol.
The client make an HTTP request , which the (web) server responds to
in the form of a response called HTTP response.

The client mostly make these two types of HTTP requests:


Introducing Django: Django is python based free and open source web
application framework. It prevents repetition of work.

Installing Django:

To install Django on Windows , follow the steps given below:

(i) Connect to internet

(ii) Start cmd (Windows 7) or Windows Power Shell (Windows 10) in


administrator mode.

(iii) go to the folder where you want to install virtual environment by


using CD command.

(iv) type the following command to download and install virtual


environment
(v) now type following command

(vi) Nowactivate virtual environment by giving activate command.

(vii) Once activated, install Django :


Creating a Project in Django:
Creating Apps of a Django Project :

First go inside the outer project folder online_shop (because


manage.py reside in it) and then issue command:

Register apps – Register apps with project after creating them.


Open inner project-name folder’s setting.py file and add apps names in
the INSTALLED APPS list.

Creating Models : Models in Django refer to the way data is stored and
processed. The data model for an app is defined inside model.py file of
the app folder.

Creating Templates : After creating apps and their models, create


templates for each app.

1. Create a folder templates inside BASIC DIRECTORY (outer project


name folder)
2. Stores desired html files inside templates folder.

3. Next , Add the name of templates folder in the DIRS settings


under TEMPLATES of setting.py file of your project (inner project
name folder)

Creating views : Next, create views. Views receive the request in the
form of URL and provide response in form of templates.

Go inside products app  views.py and define view function :


Go inside inner project folder online_shop  urls.py file and edit:

Вам также может понравиться