Introduction to Django

Jas Spencer
2 min readMar 21, 2021

Django is a framework built with the Python programming languages. It’s used to build full scare applications using Python both on the back end and front end. What’s really nice about Django and other frameworks like Rails is that they take care of a lot of the logic for you. Making easier for the programmer to focus on the functionality of the project. However there can be a but of a learning curve when learning a new framework as you need to understand how all the pieces fit together. That’s what will be discussed in this post.

A quick note concerning Virtual Environments:

Python has a feature known as a virtual environment which when setup, causes any dependencies installed to be available only in that environment which is pretty cool! This means that if you have multiple projects going, using virtual environments can help prevent any dependencies or versions of different packages getting in the way of one another. I highly recommend using virtual environments and they are easy to setup. When Python is installed you will have the package manager ‘pip’, similar to ‘npm’ for JavaScript ‘pip’ is used install dependancies and activate virtual environments. Use the command:

pip install pipenv #this installs the virtual environment dependencypipenv shell #creates virtual environment

Once the virtual environment has been set up. Any Django project can be creatred with the following command:

django-admin startproject <project name goes here>

Lots of developers will use the name ‘mysite’ for a project name but it can be almost whatever you want.

Django uses the term ‘project’ for the complete overview of what ever you’re building. Any application that’s within that project, or anything that does something is referred to as an app.

When the initial project is created, a few files will generate that essentially help to run the project. One that you should pay attention to especially is the ‘urls.py’ file which allows you to declare URLs or the different paths/routes in the project. Essentially telling the user when to navigate to.

To start up a server, we use the ‘manage.py’ file with the foloowing terminal command:

python manage.py runserver

This stars up a local server on your machine where you can see your project in action!

When it comes to creating different apps inside of the project, they are created with the following command:

python manage.py startapp <app name goes here>

Here is where you can build out views and other methods that specifically have to do with that app. That information can be passed back and forth within apps in your project.

This is the very basics of Django and I will get more into detail in future blog posts as there is much more to unpack. Django is a very fast framework that takes a lot of the dense backend setup out and makes it much easier to focus on the core of any project. If you’ve worked with other frameworks, I would highly recommend Django.

--

--

Jas Spencer

Software Engineer in NYC with expertise in Ruby on Rails, JavaScript, and React