Introduction to Django (Part 1)
#Python #Programming #Beginner #Django

Django is a free, open source web framework written in the Python programming language and used by millions of programmers every year. Django is robust enough to be used by the largest websites in the world–Instagram, Pinterest, Bitbucket, Disqus–but also flexible enough to be a good choice for early-stage start-ups and prototyping personal projects.

Lets see at the basic structure of Django and the main files one needs to work with.

URLs: URL mappers are used to redirect HTTP requests to the corresponding view based on the URL path provided in the URLs file.

View: A view acts as a handler function, which receives HTTP requests and returns HTTP responses through models and formats the data from the models so as to be accessed by the templates.

Models: Models define the structure of an application's data, and provide the CRUD functionality (Create, Read, Update, Delete).

Templates: A template is a text file defining the structure or how the file us organized, 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.

Virtual Environments

Virtual environments are an isolated container containing all the software dependencies for a given project.

It is always advisable to run Django in a virtual environment, this makes it independent and in case you want to deploy it, it will be easier for you to come up with your requirements file and also it gives you the freedom of working with different Django versions within the same computer or machine, and this not only applies to Django but any python project you might want to do.

We will make use if the pipenv command to manage our virtual environment.

To install Pipenv we can use pip3 which mostly comes pre-installed  automatically in Python 3.

$ pip3 install pipenv

The above command install the virtual environment in our specified location, so you have to run the command at your specified location.

After having that, we need now to activate our virtual environment so that we can start working in it, and we do that by running

$ pipenv shell

This will activate our virtual environment and we can start working on it.

First we now have to install Django by running

$ pipenv install django

After this is done you will be ready to work with Django though we will install some other dependencies along the way but as per now you are good to go.

Thank you for reaching this far and making some progress, in our next article we'll start by creating our first project...