首页 Django项目开发与部署视频教程 完成django项目的基本配置
pay pay

完成django项目的基本配置

日期: 六月 25, 2023, 9:42 a.m.
阅读: 97
作者: Python自学网-村长

摘要: 完成django项目的基本配置

完成django项目的基本配置

1.配置调试模式

DEBUG = True

ALLOWED_HOSTS = ['*']

 2.配置项目和富文本

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'myblog',
    'ckeditor',
    'ckeditor_uploader',
]

3.配置模板

import os
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',
            ],
        },
    },
]

 4.配置MySql数据库

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',  #
        'NAME': 'myblog',  # 新建的database名称
        'USER': 'root',  # 用户名,安装数据库时默认的
        'PASSWORD': 'XXXXXXXX',  # 数据库密码(数据库安装时设置的密码)
        'HOST': 'localhost',  # 默认,或者:127.0.0.1
        'PORT': '3306',  # MySQL默认端口
    }
}

5.配置时区和语言

LANGUAGE_CODE = 'zh-Hans'  # zh-Hans

TIME_ZONE = 'Asia/Shanghai'  # Asia/Shanghai

USE_I18N = True

USE_TZ = True

6.配置静态文件

STATIC_URL = 'static/'
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static'),
]

6.配置富文本控件

CKEDITOR_CONFIGS = {
    'default': {
        'toolbar': (
            ['div', 'Source', '-', 'Save', 'NewPage', 'Preview', '-', 'Templates'],
            ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Print', 'SpellChecker', 'Scayt'],
            ['Undo', 'Redo', '-', 'Find', 'Replace', '-', 'SelectAll', 'RemoveFormat'],
            ['Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'],
            ['Bold', 'Italic', 'Underline', 'Strike', '-', 'Subscript', 'Superscript'],
            ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', 'Blockquote'],
            ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'],
            ['Link', 'Unlink', 'Anchor'],
            ['Image', 'Flash', 'Table', 'HorizontalRule', 'Smiley', 'SpecialChar', 'PageBreak'],
            ['Styles', 'Format', 'Font', 'FontSize'],
            ['TextColor', 'BGColor'],
            ['Maximize', 'ShowBlocks', '-', 'About', 'pbckcode'],
            ['Blockquote', 'CodeSnippet'],
        ),
        'width': '800px',
        'height': '600px',
        # 添加按钮在这里
        'toolbar_Custom': [
            ['NumberedList', 'BulletedList'],
            ['Blockquote', 'CodeSnippet'],
        ],
        # 插件
        'extraPlugins': ','.join(['codesnippet', 'widget', 'lineutils', ]),
    },
}

 7.配置路由

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


urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('myblog.urls')),

    re_path(r'^ckeditor/', include('ckeditor_uploader.urls')),
    re_path(r'files/(?P<path>.*)$', serve, {'document_root': settings.MEDIA_ROOT}),

] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

 

原创视频,版权所有,未经允许,切勿转载,违者必究!
回顶部