一:
切换至目录,创建工程django:django-admin startproject joke_blog
创建应用:python manage.py startapp blog
二:
三:
数据库构建
blog/models.py
from django.contrib.auth.models import User
from django.db import models
# Create your models here.
class Category(models.Model):
name = models.CharField(max_length=100)
# def __str__(self):
# return self.name
#
# 标签
class Tag(models.Model):
name = models.CharField(max_length=100)
# def __str__(self):
# return self.name
#
class Post(models.Model):
# 标题
title = models.CharField(max_length=100)
# 正文
body = models.TextField()
# 文件创建时间和最后一次修改时间
created_time = models.DateField()
modified_time = models.DateField()
# 文章摘要
excerpt = models.CharField(max_length=200, blank=True)
category = models.ForeignKey(Category, on_delete=models.CASCADE)
tags = models.ManyToManyField(Tag, blank=True)
author = models.ForeignKey(User, on_delete=models.CASCADE)
#
# def __str__(self):
# return self.title
blog/__init__.py
import pymysql
pymysql.version_info = (1, 4, 13, "final", 0)
pymysql.install_as_MySQLdb()
数据库生成;
四:
视图关联
工程urls.py
配置项目urls.py
然后关注视图即可