django之创建第4-2个项目-访问class类属性和类方法
1、修改index
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>django之创建第4-2个项目</title>
</head>
<body>
<h1>hello,{{test.name}}</h1> <!--模板 变量用变量定义-->
<h1>hello,{{test.sex}}</h1>
<h2>访问类方法:{{test.myMethod}}</h2>
</body>
</html>
2、views.py
# Create your views here.
#coding:utf-8
from django.http import HttpResponse #导入templates文件所需导入库
from django.template import loader,Context class Person(): def __init__(self,name,age,sex):
self.name=name
self.age=age
self.sex=sex def myMethod(self):
return "get it" def index(request):
#第二个项目
#return HttpResponse("hello,Django") #加载器,加载模板
t=loader.get_template("index.html") # django之创建第4-2个项目-访问class类属性和类方法 #实例化
person = Person("xiaodeng", 28, "male")
c = Context({"test": person}) # 在这里test位变量,user为变量的值
return HttpResponse(t.render(c))
3、百度云盘:http://pan.baidu.com/s/1i5heZu1
django之创建第4-2个项目-访问class类属性和类方法的更多相关文章
- django之创建第6个项目-过滤器
1.views.PY # Create your views here. #coding:utf-8 from django.http import HttpResponse import datet ...
- django之创建第12个项目-加载图片
百度云盘:django之创建第12个项目-加载图片 1.setting配置 #静态文件相关配置 # URL prefix for static files. # Example: "http ...
- django之创建第11个项目-页面整合
目的:将如下众多html页面整合到一个index.html页面中. 百度云盘:django之创建第11个项目-页面整合 用下面的方式实现: <!DOCTYPE html> <head ...
- django之创建第10-1个项目-图片上传并记录上传时间
1.百度云盘:django之创建第10-1个项目-图片上传并记录上传时间 2.主要修改的配置文件有3个,forms.views和models3个文件以及html 3.forms.py文件修改 #cod ...
- django之创建第10个项目-图片上传方式1
1.upload.HTMl <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang=& ...
- django之创建第9个项目-管理后台admin
django之创建第9个项目-管理后台admin配置 1.配置setting文件INSTALLED_APPS = ( 'django.contrib.auth', 'django.cont ...
- django之创建第8-3个项目-数据库数据提取之高级操作
1.配置test2.html <!DOCTYPE html> <html lang="en"> <head> <meta charset= ...
- django之创建第8-1个项目-数据库之增删改查/数据库数据显示在html页面
1.为test.DB数据库预先创建下面数据 1 张三 16 2015-01-02 12 李四 17 2015-01-04 13 王五 14 ...
- django之创建第8个项目-数据库配置及同步研究
1.sqlitestudio-2.1.5数据库可视化工具--百度云盘下载 2.编写C:\djangoweb\helloworld\blog\models.py文件 # Create your mode ...
随机推荐
- Visual Studio Code compile error - launch.json must be configured...
一.在最初使用VS Code创建控制台应用时, 使用VS Code调试工具默认会跑出异常: launch: program 'launch: launch.json must be configure ...
- JavaScriptSerializer 类
ylbtech-.Net-Class:JavaScriptSerializer 类 应对 Json.NET 使用序列化和反序列化. 为启用 AJAX 的应用程序提供序列化和反序列化功能. 1.实例返回 ...
- source insight 4.0.086破解
source insight 4.0.093 破解: 1. 安装原版软件:Source Insight Version 4.0.0093 - March 20, 2018 2. 替换原主程序:sou ...
- 怎样修改SQL Server 2005/2008的系统存储过程(转)
我们知道,SQL Server 2005/2008的系统存储过程在正常情况下是无法直接修改的. 尽管本文是介绍怎样修改它的,但在这里,我还是建议大家尽量不要去修改它.(好像有点绕哈...) OK,闲话 ...
- 原生JS实现bind()函数
一.bind()函数的两个特性: 1.bind和curring,函数科里化 function add(a, b, c) { var i = a+b+c; console.log(i); return ...
- iOS开发中FMDB的使用
1.什在日常的开发中,我们需要用到离线缓存将数据信息存入数据库,在没有网络的时候进行加载,而我们IOS用的就是sqlite3数据库,用原生的sql我们也能实现,但是书写起来比较麻烦,尤其是其它语言转过 ...
- TOJ 1220 填数字游戏 / 深搜
填数字游戏 时间限制(普通/Java):1000MS/10000MS 运行内存限制:65536KByte 描述 有个小游戏,让你填写以下方框,要求: a1+a2+a3+M=b1+b2+b3+M ...
- xgboost入门与实战(实战调参篇)
https://blog.csdn.net/sb19931201/article/details/52577592 xgboost入门与实战(实战调参篇) 前言 前面几篇博文都在学习原理知识,是时候上 ...
- 转: MinGw离线安装方法集合
转自: http://www.cnblogs.com/smartdog/archive/2012/03/30/2425124.html https://www.zhihu.com/question/2 ...
- [Spring Boot] Introduce to Mockito
We have the implemetion: @SpringBootApplication public class MockitoDemoApplication { public static ...