Django Build Your own blog site (a) Introduction
This series is mainly through the use of the Django Python web framework to implement a simple personal blog site. Django has a question that can be found on the Django website.
Function
- Background management post, modify, delete
- Sub-label Management
Depend on
In addition to using Django, the page Layout section uses Bootstrap
frames, and the story editor and parser are used separately django-pagedown
markdown2
.
Install
$ pip install django$ pip install django-pagedwon$ pip install markdown2
Bootstrap can download the resource bundle on the bootstrap website and put it static
under the project directory.
Start Project
$ django-admin startproject Blog
Go to the project folder to run the command:
$ python manage.py startapp post
Create a folder under the project root directory. The source of the static
downloaded bootstrap is put here.
Run:
$ python manage.py runserver
Settings
In a Django project, settings.py
It is the configuration file for the project.
Database
The database I am using is MySQL, and the new project defaults to using SQLite, so the settings for the database need to be changed:
# settings.py= { ‘default‘: { ‘ENGINE‘‘django.db.backends.mysql‘, ‘NAME‘‘django_dev‘, ‘USER‘:‘root‘, ‘PASSWORD‘:‘123456‘, ‘HOST‘:‘127.0.0.1‘, ‘PORT‘:‘3306‘, }}
Changes will also be made later settings.py
.
Then, the project database is django_dev
, the database to be created in MySQL itself, because the site is mainly used in Chinese, so the code is set to utf-8
:
create database django_dev default character set utf8;
Time
Django default time is the United States, to use the time in Beijing, you need to change the time TIME_ZONE
zone in China, specifically, can refer to the official Django document introduction.
Install the Post app
= [ ‘post.apps.PostConfig‘, ‘django.contrib.admin‘, ‘django.contrib.auth‘, ‘django.contrib.contenttypes‘, ‘django.contrib.sessions‘, ‘django.contrib.messages‘, ‘django.contrib.staticfiles‘,]
By this point, the project is well established.
Django Build blog site (i)