Django

What is Django?

* Django is a web development framework for python which offers standard method for fast and effective website development.
* The primary goal of this high-level web framework is to create complex database-driven websites.
* It helps you to build and maintain quality web applications.
* It enables you to make the development process smooth and time saving for rapid development.


What is Framework?

* a web framework is a code library which help you to build a flexible, scalable, and maintainable, dynamic website, web app, web services.
* File design pattern: MVC, MVT



Django Architecture




Difference Between MVC and MVT Architectural Design Patterns

AspectMVC (Model-View-Controller)MVT (Model-View-Template)
ComponentsModel, View, ControllerModel, View, Template
Role of ViewDisplays the data to the user (UI)Handles the user input and interaction; processes the request
Role of TemplateN/AThe Template is responsible for rendering the HTML/CSS (View in MVC)
Role of ControllerHandles user input, processes it, and updates the ModelThe View handles both user input and response rendering, which in MVC is split between Controller and View
Responsibility SplitThe View is only concerned with rendering and displaying dataThe View is responsible for the logic of handling requests and user interactions
Data FlowUser interacts with the View, which calls the ControllerUser interacts with the View, which handles the logic and returns a Template for rendering
Framework ExamplesRuby on Rails, Angular, ASP.NET MVCDjango

Download & Install of Django

* First create Virtual Environment using Python by Following command:  python -m venv env
* Activate Virtual Environment using following Command:  env\Scripts\activate
* Install Django Using following command:  pip install Django



Creating Django Project?

* Whether you are on Windows or Linux, just get a terminal or cmd prompt and navigate to the place you want your project to be created: Django-admin startproject projectname


Create Django Framework in Visual Studio Code using following command: 


Create New Folder= folder name(Hrsikh)

Hrsikh>python -m venv env
Hrsikh>cd env/Scripts
Hrsikh\env\Scripts>activate
(env) Hrsikh\env\Scripts>pip install django
(env) Hrsikh\env\Scripts>django-admin startproject projectname .
(env) Hrsikh\env\Scripts>cd..
(env) Hrsikh\env>cd..
(env) Hrsikh>django-admin startproject projectname
(env) Hrsikh>cd projectname
(env) Hrsikh\projectname>python manage.py migrate
(env) Hrsikh\projectname>python manage.py makemigrations
(env) Hrsikh\projectname>python manage.py runserver

Project Folder File Structure

* Manage.py : This file is kind of your project local django admin for interacting with your project via command line(start the development server, sync db...).
__init__.py : Just for python, treat this folder as package.
* Setting.py : As the name indicates, your project settings.
* Urls.py : All links of your project and the function to call. A kind of ToC of your project.
* Wsgi.py : If you need to deploy project over WSGI.

Creating Application

* We assume you are in your project folder. In our main "projectname" folder, the same folder then manage.py: python manage.py startapp appname

Application Folder File Structure
__init__.py : Just for python, treat this folder as package.
Admin.py : This file helps you make the app modifiable in the admin interface.
Models.py : This is where all the application models are stored.
Test.py : This is where your unit tests are.
Views.py : This is where your application views are.



Tags

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.

#buttons=(Ok, Go it!) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Ok, Go it!