初试django
Posted oliva
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了初试django相关的知识,希望对你有一定的参考价值。
创建django程序:django-admin startproject [name]
python manage.py runserver
#字符串
return HttpResponse(‘‘)
#自动找到模板路径下的html文件,读取内容并返回给用户
return render(request,‘[html]‘)
1.创建project
2.配置
-模板路径
TEMPLATES = [
{
‘BACKEND‘: ‘django.template.backends.django.DjangoTemplates‘,
‘DIRS‘: [os.path.join(BASE_DIR, ‘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/‘ #前缀
STATICFILES_DIRS=(
os.path.join(BASE_DIR, ‘pageStyle‘), #逗号很关键不然要报错
)
3.额外配置
MIDDLEWARE = [
‘django.middleware.security.SecurityMiddleware‘,
‘django.contrib.sessions.middleware.SessionMiddleware‘,
‘django.middleware.common.CommonMiddleware‘,
#‘django.middleware.csrf.CsrfViewMiddleware‘,
‘django.contrib.auth.middleware.AuthenticationMiddleware‘,
‘django.contrib.messages.middleware.MessageMiddleware‘,
‘django.middleware.clickjacking.XFrameOptionsMiddleware‘,
]
以上是关于初试django的主要内容,如果未能解决你的问题,请参考以下文章
初试django---python manage.py makemigrations以及python manage.py migrate