Lesson 1: Getting Started with Django – Like Assembling IKEA Furniture, But Less Frustrating (Now With Virtual Environments and Django LTS!)
Welcome to the first lesson of our Django course! Today, we’re going to set up Django and kick off your very own Personal Blog project, all while wielding the legendary powers of Linux like the tech wizard you are. We’ll be using Django’s LTS version (4.2.16) because stability is king (and who wants surprises in their project, right?).
This lesson is going to be like building IKEA furniture, but with far fewer pieces left over at the end.
Note: We’re going to build this blog without using Git for version control. We’re going old-school, but if you want to be a version control pro (or just pretend to be one), check out this guide to learning Git. For now, let’s live dangerously and save everything directly on your computer!
What is a Virtual Environment (and why do we need it)?
Picture this: a virtual environment is like setting up a fort made of pillows in the living room. It’s your cozy space where all your Django goodies can live without anyone else’s snacks (read: dependencies) sneaking in. That way, when you install stuff for your project, it won’t ruin what’s happening elsewhere on your computer. It’s basically your project’s personal bubble. Keep it clean, keep it safe.
What is pip3
?
Ah, pip3
. The magical spellbook for Python 3. This little command allows you to install packages and libraries that aren’t built into Python. Think of it as Amazon Prime, but for code. Since we’re using Python 3 for this project (because who still wants Python 2?), we use pip3
. If you see pip3
, just know it’s getting Python 3 packages and not messing with your system’s Python 2 baggage.
What’s the Project? Django Personal Blog
Throughout this course, we’re building a Personal Blog. And no, it’s not just another blog – it’s your blog, your digital fortress. You can post your groundbreaking thoughts, post your cat’s glamorous photoshoot, or share your controversial opinion on whether pineapple really belongs on pizza (spoiler: it does).
Here’s what your blog will be able to do:
- Post creation and editing: You’ll be able to create, edit, and delete blog posts like a proper content wizard.
- Commenting: Visitors can leave comments (and you can moderate them, in case someone comes in with the “pineapple doesn’t belong on pizza” nonsense).
- Categories and tags: So organized it’ll put your sock drawer to shame.
- User authentication: Only logged-in users can manage posts, while the unwashed masses can read and comment.
Step 1: Install Virtualenv (If You Haven’t Already)
Before we dive into the code, we need to make sure virtualenv
is installed. This is the magic that lets us create our pillow fort (aka virtual environment) to keep the project safe from the outside world.
For Arch Linux users, you can install it using this command:
sudo pacman -S python-virtualenv
For other Linux users, use:
pip3 install virtualenv
This installs virtualenv
for Python 3. And if it fails, just blame your cat, take a deep breath, and try again.
Step 2: Navigate to Your Project Directory
Now open your terminal (Linux users basically live there anyway, right?) and move to the place where you want to store your blog. This is where you’ll build your empire. Something like:
cd ~/Documents
It’s the digital equivalent of setting up camp.
Step 3: Create the Project Directory
Time to get organized! Let’s create a directory for your blog. You’ll thank yourself later for this.
mkdir myblog
cd myblog
Boom! You’ve now got a folder named myblog
, where your blogging adventure will begin.
Step 4: Create a Virtual Environment Inside the Project Folder
Now, let’s create your project’s personal space where all the magic will happen.
virtualenv venv
A venv
folder has just appeared inside myblog
. This is where all the good stuff (aka libraries) will live.
myblog/
venv/
Step 5: Activate the Virtual Environment
Now you have to activate the virtual environment. This is like getting the party started. In Linux, it’s as easy as:
source venv/bin/activate
Your terminal will now show something like (venv)
at the beginning, which means you’re inside your magical little sandbox, and you can start doing your Django wizardry.
Step 6: Install Django LTS Version 4.2.16
Let’s summon the most stable and trustworthy version of Django (the LTS version 4.2.16). Run this command:
pip3 install django==4.2.16
Congrats! You now have the long-term support version of Django living happily inside your virtual environment. This is your safe space, no intruders allowed.
Step 7: Create Your Django Project
Now, let’s create the Django project itself. Don’t forget the .
at the end – it’s like the tiny yet vital screw in an IKEA kit. It might look unimportant, but it’s holding the whole thing together.
django-admin startproject myblog .
After this, your folder should look something like this:
myblog/
venv/
myblog/
manage.py
Look at it – it’s starting to resemble something real!
Step 8: Start the Django Server
Now for the big reveal. You’re going to fire up the server and see what all this work has been for. If your system has both Python 2 and Python 3, make sure you’re using Python 3:
python3 manage.py runserver
If your system defaults to Python 3, you can also just do this:
python manage.py runserver
Once it’s running, open your browser and visit http://127.0.0.1:8000/. You should see Django’s lovely welcome page. If it doesn’t work, just remember – even wizards have off days.
If you want to quit the server, simply hit CTRL + C
in the terminal. No, you’re not killing it. It’s just a nap.
Step 9: Deactivate the Virtual Environment
When you’re done for the day (or just need a snack break), you can leave your virtual environment by typing:
deactivate
Poof! You’re back in your regular terminal, and your virtual environment will be there waiting for you when you return. It’s like pausing a game – no progress lost.
Wrapping Up Lesson 1
Congrats! You’ve set up a virtual environment, installed Django’s LTS version (4.2.16), and even created the skeleton of your very own Personal Blog project – all while on Linux. No Git required (yet). But when you’re ready to dive into version control, Git will be there to welcome you with open arms.
Reminder: If you want to quit the Django server, just press CTRL + C
. Your server will take a nap, and you can carry on with your life.
In the next lesson, we’re going to level up your blog by adding the ability to create and manage posts. Soon, your blog will be the best thing on the internet (second only to cat memes, of course). Let’s do this!
See also
- Lesson 6: User Profiles – Because Everyone Deserves a Little Spotlight
- Lesson 5: User Registration – Because Only the Worthy Should Comment!
- Lesson 4: User Authentication – Because Not Everyone Should Have Access to Your Blog's Inner Sanctum
- Lesson 3: Forms – The Art of Asking Nicely for User Input (Without Scaring Them Away)
- Arch Linux vs. Ubuntu vs. Fedora: The Linux Family Reunion