Django(python framework)

Techno Freak
4 min readJan 25, 2023

--

Database-driven websites

Django is a high-level Python web framework that enables rapid development of secure and maintainable websites. Django takes care of much of the hassle of web development, so you can focus on writing your app without needing to reinvent the wheel.

MVT (Model-View-Template)- Django architecture

MVT is a software design pattern for developing a web application.The MVT architecture contains the three components :

  1. Model : The model is going to act as the interface of your data. It is responsible for maintaining data. It is the logical data structure behind the entire application and is represented by a database (generally relational databases such as MySql, Postgres).

2.View: A view is a place where we put our business logic of the application. The view is a python function which is used to perform some business logic and return a response to the user.It is represented by HTML/CSS/Javascript.

3. Template: A template consists of static parts of the desired HTML output as well as some special syntax describing how dynamic content will be inserted.Django mainly functions with a backend so, in order to provide a frontend and provide a layout to our website, we use templates. There are two methods of adding the template to our website depending on our needs.

Installation of Django

  • Install python3 if not installed in your system ( according to configuration of your system and OS) from docs. Try to download the latest version of python it’s python 3.11.0 this time.
  • Install pip- Open command prompt and enter following command-
python -m pip install -U pip
  • Install virtual environment- Enter following command in cmd-
pip install virtualenv

Set Virtual environment- Setting up the virtual environment will allow you to edit the dependency which generally your system wouldn’t allow.
Follow these steps to set up a virtual environment-

  1. Create a virtual environment by giving this command in cmd-
virtualenv env_site

2. Change directory to env_site by this command-

cd env_site

3. Go to Scripts directory inside env_site and activate virtual environment-

cd Scripts
activate
  • Install Django- Install django by giving following command-
pip install django
  • Return to the env_site directory-
cd .
  • Start a project by following command-
django-admin startproject techno-site
  • Change directory to techno-sites
cd techno-sites
  • Start the server- Start the server by typing following command in cmd-
python manage.py runserver

Advantages of Django

  1. Framework Support : Built -in support Caching ,Ajax, RSS and other frameworks.
  2. ORM (Object-Relational Mapping ) support : Django also supports NoSQL database through Django-nonrel fork. For now, the only NoSQL databases supported are MongoDB and google app engine.Supports a large set of database systems including MySQL, Oracle, Postgres, etc.
  3. Admin Gui : Django provides a nice ready-to-use user interface for administrative activities.
  4. Multilingual language :jango supports multilingual websites through its built-in internationalization system. So you can develop your website, which would support multiple languages.

Other Frameworks to look for >>>

Pyramid:A lightweight, scalable framework, Pyramid is used for developing small to large-scale web apps. It is also great for quick prototyping and for developers who are working on API projects.Pyramid has a small footprint but it is easily extendable with add-ons, configurations and libraries to include unique functionalities in your app. It sometimes provides so many options that it can get tough to make the right choices in a new project.Major companies such as Dropbox, Fedora, Mozilla, SurveyMonkey, and Yelp use Pyramid for website development.

Flask : Flask is a microframework that is suitable for small projects that need a fast way to make a simple, Python-powered website.It is highly scalable and thus suitable for startups. It utilizes microservices and micro-frontends, to reduce the loading time of a webpage.Flask comes with many configuration values, along with a few easily customizable defaults, and a few conventions. It also implements common security measures such as session-based management, password hashing, HTTP authentication, and cross-site request forgery(CSRF) for protection against vulnerabilities.

CherryPy : It is a python based, object-oriented web development framework. It provides built-in capital plugins and a powerful configuration system.CherryPy also includes an implementation of the Ruby programming language framework.t is a very lightweight alternative for Django and one of the oldest Python frameworks. CherryPy has built-in tools for coding static web pages, URL encoding, user authentication, and session management. It is also embedded with a powerful configuration system that can handle multiple HTTP requests and run multiple HTTP servers simultaneously.

--

--

Techno Freak
Techno Freak

Written by Techno Freak

Devops &Full-Stack enthusiast . Helping People to learn about cloud and opensource . Learning bit by bit

No responses yet