新建项目
#新建django项目myweb
django-admin startproject myweb
#新建app应用book(进入到项目中)
python manage.py startapp book
myweb/setting.py设置
#在myweb/setting.py中将book加入INSTALLEN_APPS中
#数据库设置mysql()
import pymysql
pymysql.install_as_MySQLdb()
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME':"mysite2",
'USER':"root",
'PASSWORD':'root ',
'HOST':'192.168.12.216',
'PORT':3306
}
}
#语言设置
LANGUAGE_CODE = 'zh-hans'
#时区设置
TIME_ZONE = 'Asia/Shanghai'
templates 页面设置
TEMPLATES = [
{
"DIRS":[os.path.join(BASE_DIR,"templates")],
}
#session放入Redis数据库中
SESSION_ENGINE = 'redis_sessions.session'
SESSION_REDIS_HOST = '192.168.12.216'
SESSION_REDIS_PORT = 6379
SESSION_REDIS_DB = 1
SESSION_REDIS_PASSWORD = ''
SESSION_REDIS_PREFIX = 'session'
#发送邮件设置
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
EMAIL_HOST = "smtp.qq.com"
EMAIL_PORT = 25
EMAIL_HOST_USER = "3127275592@qq.com"
EMAIL_HOST_PASSWORD = "trmyjoebwuojdeaf"
EMAIL_FROM = "天天生鲜<3127275592@qq.com>"
由数据模型生成表
python manage.py makemigrations
python manage.py migrate
#根据数据库表生成数据模型
python manage.py inspectdb > app/models.py
获取当前页面的url
获取带参数URL:request.get_all_path()
获取不带参数URL:request.path
获取主机地址:request.get_host()