Web Programming with Django - An Introduction

Web Programming with Django - An Introduction

ยท

3 min read

Introduction

Building a website using HTML and CSS is pretty trivial. Just build a structure implement some styling and voila. But a website or a webpage built using just HTML and CSS is a static web page i.e., Every time a user visits a page it will be the same, the user cannot make any requests from the page. In order to make it Dynamic and respond to requests made by the user, we have to create a server of this website. But we cannot do it using HTML because HTML is a Markup Language not a Programming Language. So in this Blog we are going to see how can we use a programming language such as Python to create a whole server of a website.

What is Django and Why do we need it?

Building a server from scratch can be a pain. Its not just as easy as creating the structure of a website and add styling to it (lol๐Ÿ˜‚). But to make our lives easier, programming languages have a certain set of Frameworks that provides us with some starter files and a particular steps to follow. These frameworks have a certain functionalities and prewritten code that gives us advantage to avoid writing everything from scratch and focus on how to actually implement those functionalities into a working code for our website. Unlike Libraries frameworks have a structure and some best practices that we need to follow if we want to make our website future easily editable and dynamic.

Installation

If you are working with python you might be familiar with pip the python package installer. Go to your terminal and type pip install django once installed type pip show django to make sure that its installed properly.
Installation Done!

Image description

Creating a Project

To get started with django open the terminal and type python -m django startproject PROJECT_NAME

Image description

This will create a project directory in your directed folder with a file named manage.py and another folder with name same as your PROJECT_NAME.

Image description

Project Creation Done!

Creating an App

Every website contains some different webpages or subpages that we can visit in order to enjoy different features of a website. For Example Google have Google Search and Google Images and Google Maps and Google News etc.
These are all examples of webapps of a common project named Google.
Similarly in order to create different apps for our project open the terminal and type cd PROJECT_NAME now you are in the project directory. Now type python manage.py startapp APP_NAME

Image description

Image description

This will create an App with various starter files. Now type cd myapp and then ls to check see these files.

Image description

Configuration Settings

While creating our project and our app we have seen various files.
Such as in our project directory we saw __init__.py asgi.py wsgi.py ๐Ÿ‘ˆ๐Ÿป We don't have to worry about these files for now.
But when we open our settings.py file and go into the INSTALLED APPS section, we still don't see the app that we have just created.

Image description

So go ahead at install our App by entering our APP_NAME into the INSTALLED APPS

Image description

Congratulations you have successfully created you first Django Application

Summary

Install Django
Create Project python -m startproject PROJECT_NAME
Create an App using manage.pypython manage.py startapp APP_NAME
Go to settings.py set-up app configurations

ย