How to create a simple blog using Django 3 - part 1

/ #Django


In this tutorial series I'm going to show you how to create a simple blog using Django 3. It's going to look similar to this exact blog.

Content

In the first part of this series we're going to cover how you set up a Django environment on your Mac and check that it's working as expected. Througout this series we're going to cover everything you need to create a simple blog.

The result will be a blog similar to this one. We are going to make it possible to create posts and putting them in categories. Visitors will also be able to add comments to the posts and there will be a very simple search.

Setting up a Django/Python environment

The first thing we need to do is to create a space where Django and Python can run. To make it as portable and maintainable as possible, we're going to use something called a virtual enviroment. If you've got a Mac, you need to install Brew.

When you've got Brew installed, open up a terminal and write the following to install virtual environment and create one afterwards.

// Install virtualenv
sudo pip install virtualenv

// Create a new enviroment
virtualenv myblogenv

A new folder called "myblogenv" with will be created. If you want to call it something else, feel free to do so. In order to use the virtual environment we just created, we need to run one more command.

// Navigate to the folder
cd myblogenv

// Activate the enviroment
source bin/activate

The virtual enviroment should now be ready and we can proceed to install Django.

Installing Django

It's actually really easy to install Django. Just go back to your terminal and type the following command.

python -m pip install Django

To confirm that Django has been installed, you can open up a Python interpreter by typing "python" in your terminal and hit enter. When the shell has opened, type the following commands:

>>> import django
>>> print(django.get_version())
3.0.0

Nice! Everything is ready and we can create the Django application.

Creating the Django application

Go back to your terminal and run the following command:

$ django-admin.py startproject myblog

This will create a new folder called "myblog" which is the name of our project. You can name it something else if you want to.

Check if it works

Now that the virtual environment is up and running, Django is installed and the project is created, it's time to check if it works. Type the following command in you terminal:

$ python manage.py runserver

When the server has started, open up a browser and head to http://127.0.0.1:8000.

You should now see the default Django welcome page. Congratulations, the project is ready :-D

The next part

In the next part of this tutorial series we're going to cover what the different files of the project is and we're going to create the blog app and discuss that a little bit. Sign up to my newsletter to make it easier to stay up to date with my content.

If you run in to a problem or something with this post, feel free to leave a reply below!

How to create a simple blog using Django 3 series

Part 1 - Installation
Part 2 - File structure
Part 3 - Database models
Part 4 - Admin interface
Part 5 - Creating some templates
Part 6 - Views and URLs
Part 7 - Category views
Part 8 - Media files
Part 9 - Comments
Part 10 - Search


Comments

No comments yet...

Add comment

Subscribe to my newsletter