Create a Blog using Django Framework

Create a Blog using Django Framework

Clock Icon2022.01.21

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

What is Django

Django is a free and open source web application framework written in Python. A framework is nothing more than a collection of modules that make development easier. They are grouped together, and allow you to create applications or websites from an existing source, instead of from scratch.

This is how websites – even simple ones designed by a single person – can still include advanced functionality like authentication support, management and admin panels, contact forms, comment boxes, file upload support, and more. In other words, if you were creating a website from scratch you would need to develop these components yourself. By using a framework instead, these components are already built, you just need to configure them properly to match your site.

Steps to Install Django

Step 1: Install the Latest version on Python.

brew install python3

Step 2: Install Virtual Environment for Python. The venv module provides support for creating lightweight “virtual environments” with their own site directories, optionally isolated from system site directories. Each virtual environment has its own Python binary (which matches the version of the binary that was used to create this environment) and can have its own independent set of installed Python packages in its site directories.

sudo pip install virtualenv

Step 3: Create Virtualenv Directory.

virtualenv DjangoFolder

Step 4: Now, create a new project called ‘blog’ within the Environment folder. Type in the following command and hit enter to do so.

django-admin startproject blog

Step 5: Now let's migrate and run the server.

python manage.py migrate

python manage.py runserver

Now after running the server go to web browser and type in localhost:8000

Now create a superuser

Create a new Django App:

python manage.py startapp newblog

Now open the newblog folder in any IDE(ex:- Visual Studio Code). Go to settings.py and add the name of the new Django file.

Now in the admin.py register the POST which is used to the display the blog post.

Then create the Model where the fields are required to create a blog.

Now make migration to the database.

python manage.py makemigrations

python manage.py migrate

python manage.py runserver 

Now the data has been migrated to the database and run the server.

Share this article

facebook logohatena logotwitter logo

© Classmethod, Inc. All rights reserved.