Bootstrap

Django项目实战(附源码免费下载)

制作图书管理系统(末尾附源码)
第一步先更改settings.py里面的必要配置,更改或附件项如下

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',  
    'front', #注册front
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    # 'django.middleware.csrf.CsrfViewMiddleware', 将此项先注释掉,避免post请求失败
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

TEMPLATES = [
    {
   
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR,'templates/')], #添加html文件的路径
        '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',
            ],
            'builtins':['django.templatetags.static'] #写入此项,后续添加static标签不用load
        },
    },
]

数据库更改
DATABASES = {
   
    'default': {
   
        'ENGINE': 'django.db.backends.mysql',
        'NAME':'test',
        'PORT':'3306',
        'USER':'root',
        'PASSWORD':'123456',
        'HOST':'localhost',
    }
}

urls.py里面加载文件路径如下:

urlpatterns = [
    path('',views.index,name='index'),
    path('add_book',views.add_book,name='add_book'
;