Diving into Django

Diving into Django

No alt text provided for this image


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.

No alt text provided for this image


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

No alt text provided for this image



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

No alt text provided for this image


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

No alt text provided for this image


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/

No alt text provided for this image


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

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

No alt text provided for this image
No alt text provided for this image

Congratulations🥳

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

No alt text provided for this image


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

No alt text provided for this image


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.


No alt text provided for this image


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

No alt text provided for this image



Congratulations🥳

You've installed Django 🖐️🎤

No alt text provided for this image


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.


No alt text provided for this image


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

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

No alt text provided for this image


In the terminal type: $ ls

You should see the project that you just created.

No alt text provided for this image


Let's take a look inside!

In the terminal type:

$ cd theHelloDjangoProject/

$ ls


No alt text provided for this image


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

No alt text provided for this image


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

Go ahead... Check it out.

No alt text provided for this image


Guess what you JUST DID?!


You Created Your Very First Django Project

No alt text provided for this image





theHelloDjangoApp

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

No alt text provided for this image


WRITTEN BY

Leo D. Penrose

I'm a Software Engineer from Chicago, IL. I graduated with a Computer Science degree from DePaul University and currently attending a coding bootcamp for military veterans called CodePlatoon in Chicago.

To view or add a comment, sign in

More articles by Leo D. Penrose

Others also viewed

Explore content categories