django入门 Templates介绍
来源:互联网 发布:suse linux 配置ip 编辑:程序博客网 时间:2024/05/19 02:04
什么是Templates
HTML文件
使用django模板语言(Django Template Language, DTL)
创建Templates
在APP应用根目录创建templates目录
在templates目录下创建HTML文件
views.py返回render
from django.shortcuts import renderfrom django.http import HttpResponse# Create your views here.def index(request): return render(request,'index.html')
浏览器报错:TemplateDoesNotExist
本人用的是django 1.10.2 版本
并没有自动识别,原因是
INSTALLED_APPS中未添加APP应用名
如果非要放在其他目录中,方式:
修改settings.py
TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [os.path.join(BASE_DIR, "blog\\templates").replace('\\','/')], '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', ], }, },]
添加了
'DIRS': [os.path.join(BASE_DIR, "blog\\templates").replace('\\','/')],指明路径之后,浏览器展示正常。
阅读全文
0 0
- django入门 Templates介绍
- Django&templates
- Django Templates的设置
- django学习--templates模板
- django 引用static templates
- Django之templates
- Django框架-Templates进阶用法
- django templates setting 地址设置
- django 1.8 app add templates
- django(views、urls、templates)
- Django学习(六)(模板templates)
- 初识Django-模版文件templates
- live templates简单介绍
- Django框架学习-Templates进阶用法
- Python Web开发Django、Flask之Templates
- 二 Django 1.5.4 Views and Templates
- python学习之--Django--初次使用templates
- django中templates在settings的配置
- Matlab/Simulink之STM32开发
- Redis配置文件参数说明
- 类的无参方法
- CSS3 box-sizing 属性
- 一、hibernate简单搭建小实例
- django入门 Templates介绍
- 最近公共祖先(LCA)之树上倍增法
- 数组的动态初始化
- 学习记录(4)
- 从零开始打jar包
- 一键分享
- Mybatis逆向工程
- hdu 3826 Hand in Hand 同构图★
- 见过最好的神经网络CNN解释