Create a simple django project

First, the installation environment that you need, python and django environment package (herein environment win7 + python 3.6.5 + django 2.1.5)

Second, use the command line to enter the cd command to create the required project path, and then enter the following command to create a project, where name is the name of the project

django-admin startproject name

Third, the command line into the next project just created a good path, and then enter the following command to create APP, APP where app_name is the name of the project can create multiple APP.

python manage.py startapp app_name

Fourth, modify the configuration file settings

Modification allows access to the host:

# 指定被访问的主机。若元素为'*',表示所有同一局域网内的网络均可被访问
#测试时可填为'localhost', '127.0.0.1'
ALLOWED_HOSTS = ['localhost', '127.0.0.1']

 The new name added to the APP INSTALLED_APPS (APP here is my rbac, web):

# App加载
# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'rbac',
    'web'
    # 'django.contrib.humanize',      # 人类可读性过滤器
    # 'django.contrib.sitemaps',      # 网站地图
]

Modify Admin Language:

LANGUAGE_CODE = 'en-us' # 中文简体是'zh-hans',Admin后台管理系统的页面语言随之改变

:( manually modify the database in the new mysql database, the database if no declaration, django unable to connect) (mysql database management tool with navicat more convenient)

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'rbac_edu_document', #数据库名
        'USER':'root',#登录数据库用户名
        'PASSWORD':'admin',#登录数据库密码
        'HOST':'127.0.0.1',#主机名
        'PORT':'3306',#端口号
    }
}

 

At this time, the input python manage.py runserver command line can be seen in the following information:

Then you can access this program by visiting 127.0.0.1:8000 in your browser.

You can see the prompt is displayed in the database are not synchronized, you can run  python manage.py makemigrations 项目名 the model added to the cache, then returns a number, enter python manage.py migrate to build the table, it will django model layer model built in the declaration of class in the database table, and through  python manage.py sqlmigrate 项目名 编号 you can view the specific changes to the database cache once done. After users create a super built with python manage.py createsuperuser, enter the user name, email, password. Python manage.py runserver to start the project again, this time to enter django admin interface by accessing 127.0.0.1:8000/admin.

 

Published 24 original articles · won praise 30 · views 50000 +

Guess you like

Origin blog.csdn.net/yufen9987/article/details/88391988