python3+django跳转前端html
1.项目下新建文件夹templates
2.setting.py下修改 TEMPLATES 的 DIRS
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
#'DIRS': [],
'DIRS': [str(BASE_DIR) + "/templates"], # 修改位置
'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',
],
},
},
]
3.新建.py测试
htmlTest.py
from django.shortcuts import render
def index(request):
context = {}
context['first'] = 'My first DjangoWeb!'
return render(request, 'index.html', context)
4.配置urls.py
5.文件夹templates下新建index.html
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>{{ first }}</h1>
</body>
</html>
运行程序,输入路径网址 http://127.0.0.1:8000/fisrtHtml
完成!!!!