1、新建APP
python manage.py srartapp appname #创建APP应用
2、settings设置
设置时区和语言
Django默认使用美国时间和英语,在项目的settings文件中,如下所示:
# Internationalization
# https://docs.djangoproject.com/en/1.11/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
我们把它改为亚洲/上海
时间和中文,注意USE_TZ 改成False了。
# Internationalization
# https://docs.djangoproject.com/en/1.11/topics/i18n/
LANGUAGE_CODE = 'zh-hans' # 这里修改了
TIME_ZONE = 'Asia/Shanghai' # 这里修改了
USE_I18N = True
USE_L10N = True
USE_TZ = False # 这里修改了
在INSTALLED_APPS中添加appname:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
# 'myapp.apps.MyappConfig',
'myapp', #添加APP
]
设置数据库连接:
DATABASES = {
'default': {
# 'ENGINE': 'django.db.backends.sqlite3',
# 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
'