Computer Project On Django App Creation Theory Part

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 11

⇒Django is a high-level Python web framework

that enables rapid development of secure and


maintainable websites.

⇒ It is free and open source, has a thriving and


active community, great documentation, and
many options for free and paid-for support.

⇒High-profile sites that use Django include:,


Instagram, Knight Foundation, MacArthur
Foundation, Mozilla, National Geographic, Open
Knowledge Foundation, Pinterest, and Open
Stack
WEB-FRAMEWORK

A FRAMEWORK IS A SOFTWARE TOOL THAT


PROVIDES A WAY TO BUILD AND RUN
DYNAMIC WEBSITES AND WEB-ENABLED
APPLICATIONS.

A WEBFRAMEWORK DOES MAJORITY OF


WORK AND UTILIZE YOUR CODE.

Generally, frameworks provide support for a


number of activities such as interpreting
requests (getting form parameters, handling
cookies and sessions), producing responses
(presenting data as HTML or in other formats),
storing data persistently, and so on.
Before we begin creating your own website and
launch it to the Internet, it’s important to know
how websites work.

Here are some basic terms:

 A website is simply a collection of web pages of


codes – codes that describes the layout, format
and content on a page.

 The web server is a internet-connected


computer that receives the request for a web
page sent by your browser.

 The browser connects your computer to the


server through an IP address. The IP address is
obtained by translating the domain name. (Don’t
worry, this part is all done automatically by your
browser so you don’t have to look up the IP
addresses yourself.)
In this pattern 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).
MVT Architecture
View: A view is a request handler function, which
receives HTTP requests and returns HTTP responses.
Views access the data needed to satisfy requests via
models, and delegate the formatting of the response to
templates.
Models: Models are Python objects that define the
structure of an application's data, and provide
mechanisms to manage (add, modify, delete) and query
records in the database.
Templates: A template is a text file defining the
structure or layout of a file (such as an HTML page),
with placeholders used to represent actual content. A
view can dynamically create an HTML page using an HTML
template, populating it with data from a model. A
template can be used to define the structure of any
type of file; it doesn't have to be HTML.
URLs: While it is possible to process requests from
every single URL via a single function, it is much more
maintainable to write a separate view function to
handle each resource. A URL mapper is used to redirect
HTTP requests to the appropriate view based on the
request URL. The URL mapper can also match particular
patterns of strings or digits that appear in an URL,
and pass these to a view function as data.

Installing and configuring Django


Step 1 :- Create a directory PROJECT in your hard drive.
Folder location:-

C:\PROJECT\

Now move to the directory “PROJECT” by CD command

Step 2 :- Install virtualenv –

c:\PROJECT>pip install virtualenv.

Step 3 :- Create virtual environment –

C:\PROJECT>virtualenv venv

Step 4 :- activate virtual environment:-

C:\PROJECT>VENV\Scripts\activate

Step 5 :- After activation install DJANGO using command-

pip install django

Step 6 :- Create a django project –

(venv) C:\PROJECT>Django-admin startproject

<project name>
Basic working of django
environment

manage.py - The manage.py script is used to create


applications, work with databases, and start the
development web server. It uses a command line approach
(python manage.py <tool to run>). A detailed list of actions
can be obtained by running “<path>\python manage.py help”

__init__.py - It is an empty file that instructs Python to


treat this directory as a Python package.

settings.py - It contains all the website settings. This is


where we register any applications we create, the location
of our static files, database configuration details, etc.

urls.py - It defines the site url-to-view mappings. While


this could contain all the url mapping code, it is more
common to delegate some of the mapping to particular
applications, as you'll see later

wsgi.py - It is used to help your Django application


communicate with the web server.
Creating Django App

Step 1 :-Stop the Server, if running, by pressing CTRL+ C

Step 2 :-From inside the project folder (while still in


virtual environment) type the following command:

(venv) C:\PROJECT>django-admin startproject


<registeration>

This will create a folder named “registeration” in the


“PROJECT” with the following files:-

admin.py – This file helps you make the app modifiable


in the admin interface.

apps.py – This is a configuration file of the app itself.

models.py – here is where we define the entities of


our Web application. The models are translated
automatically by Django into database tables.

views.py – his is the file where we handle the


request/response cycle of our Web application.

tests.py - this file is used to write unit tests for the


app.
Bibliography

 COMPUTER SCIENCE WITH PYTHON


WITH SUMITA ARORA
www.wikipedia.com
www.google.com (background image)
GET Method
 GET is used to request data from a specified resource

 http://localhost:8000/display?rollno=100&name=ashok

 In the above example the data is sent through the HTTP


header and is visible in the address bar

 GET request can be cached


 GET request remain in browser history
 GET request can be bookmarked
 GET request should never be used for
sending sensitive information
 GET request have length restrictions
 GET request is generally used to request data
and not to modify it.
POST Method
POST method is used to send data to a
server to create or modify a resource

 POST requests are never cached


 POST request do not remain in
browser history
 POST requests cannot be
bookmarked
 POST request have no restrictions
on length
 POST request are not visible in the
HTTP header and are send as an
attachment to the server.

You might also like