BBS导入模块

BBS项目每个文件需要导入模块及其语句汇总

一、urls.py文件

from django.contrib import admin
from django.urls import path, re_path
from app01 import views
from django.views.static import serve
from django.conf import settings

二、views.py文件

import json

from django.shortcuts import render, HttpResponse, redirect
from app01 import myforms
from app01 import models
from django.http import JsonResponse
from django.contrib import auth
from django.contrib.auth.decorators import login_required
from app01 import mypage
from django.db.models import Max, Min, Sum, Count, Avg
from django.db.models import F



from PIL import Image, ImageFont, ImageDraw

"""
Image           产生图片
ImageFont       字体样式
ImageDraw       画笔对象
"""
from io import BytesIO, StringIO
"""
BytesIO         在内存中临时存储 读取的时候以bytes格式为准
StringIO        在内存中临时存储 读取的时候以字符串格式为准
"""
import random

三、admin.py文件

from django.contrib import admin
from app01 import models
# Register your models here.

'''只要注册了 admin就会自动生产针对该注册表的增删改查至少四个功能'''
admin.site.register(models.UserInfo)
admin.site.register(models.Site)
admin.site.register(models.Article)
admin.site.register(models.Category)
admin.site.register(models.Tag)
admin.site.register(models.Article2Tag)
admin.site.register(models.UpAndDown)
admin.site.register(models.Comment)

四、models.py文件

from django.db import models
from django.contrib.auth.models import AbstractUser

五、settings.py文件

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')]  # 首要修改的配置
        ,
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]
# 数据库配置
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'bbs',
        'USER': 'root',
        'PASSWORD': '123',
        'HOST': "127.0.0.1",
        'PORT': 3306,
        'CHARSET': 'utf8'
    }
}
'''关于时区需要修改配置这里两个参数'''
# TIME_ZONE = 'UTC'
TIME_ZONE = 'Asia/Shanghai'

USE_TZ = False


'''静态文件配置'''
STATIC_URL = '/static/'
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static')
]

'''auth表要注册一下'''
AUTH_USER_MODEL = 'app01.UserInfo'

LOGIN_URL = '/login/'

'''自定义媒体文件配置'''
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
posted @ 2023-01-14 19:09  阿丽米热  阅读(32)  评论(0编辑  收藏  举报
Title