DEV Community

loading...
Cover image for Create own Blog app in Django [Tutorial]

Create own Blog app in Django [Tutorial]

soniarpit profile image CodeSnail 🐌 ・2 min read

Blog Features

  • CKEditor in Admin
  • Threaded Comment system
  • Tagging functionality
  • Retrieving similar posts
  • Search functionality
  • Auto Sitemap

So Let's start

Virtual Environment Setup

Virtualenv is a tool used to create an isolated Python environment. This environment has its own installation directories that doesn’t share libraries with other virtualenv environments (and optionally doesn’t access the globally installed libraries either).

Installation

to install virtual environment just type following command in the terminal.

pip3 install virtualenv
Enter fullscreen mode Exit fullscreen mode

Before making a virtual environment we make project directory. Inside it, we make a virtual environment. Type following command in terminal.

mkdir awwblog
Enter fullscreen mode Exit fullscreen mode

Inside awwblog directory we setup virtual environment. Type following command in terminal.

cd awwblog/
Enter fullscreen mode Exit fullscreen mode

First find your python installation path of particular version,

which python3.9
Enter fullscreen mode Exit fullscreen mode

I use python3.9 here. By above command you get the path of the python3.9 (of any version)

I want python3.9 in my virtual environment. So let’s create virtual environment.

Using virtualenv command we created env_awwblog virtual environment. Every python installation goes inside that. But before installing python stuff we need to activate the virtual environment.

Type following command.

source env_awwblog/bin/activate
Enter fullscreen mode Exit fullscreen mode

No, we are ready to install Django inside virtual environment. So let’s go…

Installing Django

pip3 install Django
Enter fullscreen mode Exit fullscreen mode

Now Django is installed in our environment

Creating awwblog Project

Everything going fine right. Now we start the project using django-admin command.

django-admin startproject awwblog
Enter fullscreen mode Exit fullscreen mode

The command should have created a awwblog directory. Use the command cd awwblog to go into the directory.

The command should have created a awwblog directory. Use the command cd awwblog to go into the directory.

python3 manage.py runserver
Enter fullscreen mode Exit fullscreen mode

Just hit the url http://127.0.0.1:8000/ in browser.
Now you can see this,

If you see this in your browser, congratulation!! your Django installation is done successfully. Now we create an app.

Creating blog App

Now let’s create your first Django application. You will create a blog application from scratch. From the project’s root directory, run the following command

python3 manage.py startapp blog
Enter fullscreen mode Exit fullscreen mode

Open awwblog directory in your favorite code editor. I am using VS code. Below is the structure of how our project file structure looks like after setting up everything,

Now open settings.py in the awwblog directory. The first thing you need to do is to add the created app “blog” in the INSTALLED_APPS.

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'blog',
]
Enter fullscreen mode Exit fullscreen mode

This holds the Django apps you’ll be using in the Django project.

That’s it for this article. In next tutorial we will build post modal to store blog posts.

Hope you like it. Please share this tutorial with your friends.

Next: Next: Designing the blog data schema – Django Blog #2

Discussion (0)

pic
Editor guide