A Quick Guide to Setting Up Your Very First Django Project

ldpenrose

Leo D. Penrose

Posted on April 4, 2023

A Quick Guide to Setting Up Your Very First Django Project

Code Coding GIF by EscuelaDevRock

Have you been eager to start building web applications with Python but don't know where to begin? Look no further than Django! As a beginner-friendly web framework, Django offers a powerful and flexible platform for developing web applications quickly and efficiently. In this blog, I'll guide you through the process of starting your first Django project and help you take your first steps toward building your web application.

Vintage Technology GIF by Beeld & Geluid

As a new developer myself, I found setting up a Django project to be a daunting task. With the numerous options and configurations available, it's easy to get lost and frustrated. However, after several attempts, I was finally able to create my first Django project and realized that the process was not as difficult as I had initially thought. That's why I'm writing this article - to help fellow beginners overcome the confusion and simplify the process of starting their first Django project. With this guide, I hope to make the process much more manageable and approachable for anyone who is just starting with Django.


Installing Django

  • Create a Virtual Environment

  • Activating The Virtual Environment

  • PIP Install Django

Creating a Virtual Environment

Before we install Django, we want to create a virtual environment. A virtual environment allows us to have an environment where we can install all of our dependencies for our project. This is great because it allows us to keep track of what versions of dependencies we use. We could run into problems if we used a version of say Django 1.1 on a project on one computer and then try to work on that same project with Django version 4.0 on another computer. Creating a virtual environment is simple by using the terminal.

Make sure that you're currently in the directory where you want your project to be.

In the terminal type: pwd

This prints the current directory

I'm currently in my DjangoPlayground folder... seems like as good of a place as any to create a new Django project to me.

TV gif. Elmo from Sesame Street tilts his head and shrugs as if to say, "I dunno."

Next while in the terminal we'll create a new folder for our project, let's call it Hello Django: $ mkdir helloDjango

Now that we have a folder created for our project, let's change directories into that folder: $ cd helloDjango/

In this directory is where we'll create our virtual environment.

In the terminal type: $ python -m venv .venv

Congratulations🥳

You've created a brand new Virtual Environment 🖐️🎤

Muppets gif. Elmo wears a yellow pointed party head, throwing his head back and shaking his bum as he dances.

Now let's get to work.

Activating Our Virtual Environment

Now that we've created this virtual environment, we have to activate it. Luckily for us this is easier than it sounds.

While still in the terminal type: $ source ./.venv/bin/activate

That's all... It's activated.

Notice the (.venv).

We are now inside our Virtual Environment.

Look at this place...so much room for dependencies.

step brothers bedroom GIF

Installing Django

So up to this point, we have created a directory, created our virtual environment inside of that directory, activated our virtual environment, and now it's time for installing Django.

While still in the terminal type: $ pip install django

Congratulations🥳

You've installed Django 🖐️🎤

Muppets gif. Elmo wears a yellow pointed party head, throwing his head back and shaking his bum as he dances.

But we're not done yet. Let's get to work setting up your very first project.


The Django Project

  • Django-Admin

  • manage. py

Django-Admin

django-admin is Django’s command-line utility for administrative tasks. You can read more about it on Django's Offical Docs.

We're going to use it to create our project called theHelloDjangoProject.

While still in the terminal type: $ django-admin startproject theHelloDjangoProject

In the terminal type: $ ls

You should see the project that you just created.

Let's take a look inside!

In the terminal type:

$ cd theHelloDjangoProject/

$ ls

manage. py

manage. py is automatically created in each Django project. It does the same thing as django-admin but also sets the DJANGO_SETTINGS_MODULE environment variable so that it points to your project’s settings. py file. You can read more about it on Django's Offical Docs.

We'll see manage. py again later.

But before we go, let's run our server.

In the terminal type:

$ python manage.py runserver

We now have our project's server running at: http://127.0.0.1:8000/

Go ahead... Check it out.

Guess what you JUST DID?!

You Created Your Very First Django Project

Blue Collar Work GIF by Pudgy Penguins


theHelloDjangoApp

Now that we have our project created in the next article, let's go a bit further and create our first 'App'.

Playing To Be Continued GIF by goodboy noah

💖 💪 🙅 🚩
ldpenrose
Leo D. Penrose

Posted on April 4, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related