Django-The Noob’s Guide

Srivastava
5 min readJun 29, 2021

Have knowledge of PYTHON, wanted to step into Web Development ?

Python being one of the leading programming languages, there is no scarcity of frameworks for Python. It provides you numerous frameworks to help you with Web Development. Frameworks of Python includes Django, Flask, Web2Py, CherryPy, AIOHTTP, Pyramid, and few more. Out of many frameworks, the most popular and widely used frameworks are

  • DJANGO
  • FLASK

DJANGO in Web Development

What is DJANGO?

As stated by Django

It is a high-level Python Web framework that encourages rapid development and clean, pragmatic design. Built by experienced developers, it takes care of much of the hassle of Web development, so you can focus on writing your app without needing to reinvent the wheel. It’s free and open source.

Django is basically a free, open-source and full-stack web application framework written in Python. It focuses on making web development process efficient and quick. Its is simple to use once you understand how to connect things as it comes with prepackaged that can be directly used .

Calling Django a Full-Stack Framework means, it includes everything that is needed to build a web application. It follows MVT(Model View Template) pattern.

  • Model helps to handle database. It can be understood as a data access layer which handles the data.
  • View is used to execute logic and interact with models to carry data and renders a template.
  • Template is a presentation layer which handles User Interface part completely.

MVT is basically MVC (Model View Controller) where View works as controller between the model(database) and the pages, and Template works as views for displaying content on pages.

Why Django?

Django being a fully stacked web framework is a collection of modular tools that can be directly used instead of creating them from scratch. Functionalities like, the ability to connect with database, setting up URL routes or patterns, security, displaying content on templates/pages, etc are provided or can be made easily using Django .

Django inherites Python’s “Batteries-Included”. Now what is this “batteries included”?

It simply means that Django comes with most of the libraries and tools required for common use cases, and include out-of-the box support. Django ORM( object-relational mapping), Middlewares, Authentication, HTTP libraries, Multi-site support, Admin interface, template engine , multiple database backend support etc, are some of the “batteries”. This makes works easier.

Now, let’s get started with Django.

Initial setup

  • cmd/terminal /shell/powershell
  • python
  • virtual environment

The question can arise why Virtual environment?

Virtual environments are indispensable(absolutely necessary) part of Python programming, that can be understood as the isolated container containing all the dependencies of the project. It helps to keep your current project or programs isolate from the pre-written once.

Setting up virtual environment for our Django Project

pip install pipenv

Activating Virtual environment

  • for Windows run :
virtualenv .
.\Scripts\activate
  • for shell/terminal run:
virtualenv env
source env/bin/activate

Although, they are not important if you are smart enough to keep projects separate while working on same computer.

Installing Django

Install django using the following commands:

pip install Django

Check whether the Django is installed successfully

open powershell /terminal and run

django-admin

If that runs successfully that means that Django is installed successfully. Here you can see the list of the core Django commands .

Getting started with our first Django Project

run the following commands to make new project

django-admin startproject test_project

on running this Django by default will create this directory structure

here you can notice that folder with “test_project” is created and on navigating to it to another folder with same name along with a file named “manage.py” exists. This might be confusing for some people like me.

Here’s the solution to it , add ( . ) at the end of the project name , this is called period

django-admin startproject test_project .

the period at the end of the statement directs the django-admin to make the project in the current directory rather than making its own project directory in our current working directory which results in ,

It doesn’t really matters to add the period at the end or not , but its just a way to not get confuse with the project folder name inside the directory folder with directory folder name.

Now lets confirm everything is working file by running Django’s local web server. Navigate inside your directory and run command in cmd/shell/terminal or in you text-editor terminal

python manage.py runserver

Now if you visit http://127.0.0.1:8000/ you should see the following image.

to stop the server press “Ctrl+c”.

You might get some errors like “You have 18 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.”, but for now leave it as it is.

--

--