Django framework installation, project creation

Django framework installation, project creation

Select the method of installing Django version 1.11.21 (the latest LTS version)

django directory management

mysite/
├── manage.py  # 管理文件
└── mysite  # 项目目录
    ├── __init__.py
    ├── settings.py  # 配置
    ├── urls.py  # 路由 --> URL和函数的对应关系
    └── wsgi.py  # runserver命令就使用wsgiref模块做简单的web server

Command line to create the project django project

  • Next find a file used to create the project folder, shift key + right mouse button to bring up the command line, enter django-admin

  • Then enter django-admin startproject mysite (project name can be changed) to create a django project

Command line start (must be performed under the project file)

  • Profiles

  • Browser access

  • Changing the port

  • Change ip and port

pychrm create project

pychrm start the project

Profile settings (restart to take effect)

#配置文件路径模板
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, "template")],  # template文件夹位置
        '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',
            ],
        },
    },
]
#静态文件配置:
STATIC_URL = '/static/'  # HTML中使用的静态文件夹前缀
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "static"),  # 静态文件存放位置
]

Guess you like

Origin www.cnblogs.com/guokaifeng/p/11007356.html