1、index

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>django之创建第4-2个项目</title>
</head>
<body>
<h2>访问list数据,用索引获取list内的数:{{test.0}}</h2> <!--模板 变量用变量定义-->
<h2>访问list数据,用索引获取list内的数:{{test.3}}</h2>
<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-3个项目-访问list数据
book_list = ["python","c++","ruby","php"]
c = Context({"test": book_list}) # 在这里test位变量,book_list为变量的值
return HttpResponse(t.render(c))

3、百度云盘:http://pan.baidu.com/s/1nuTzELr

django之创建第4-3个项目-访问list数据的更多相关文章

  1. django之创建第4-1个项目-访问dict数据

    1.修改index.html文件 <!DOCTYPE html> <html lang="en"> <head> <meta charse ...

  2. django之创建第6个项目-过滤器

    1.views.PY # Create your views here. #coding:utf-8 from django.http import HttpResponse import datet ...

  3. django之创建第12个项目-加载图片

    百度云盘:django之创建第12个项目-加载图片 1.setting配置 #静态文件相关配置 # URL prefix for static files. # Example: "http ...

  4. django之创建第11个项目-页面整合

    目的:将如下众多html页面整合到一个index.html页面中. 百度云盘:django之创建第11个项目-页面整合 用下面的方式实现: <!DOCTYPE html> <head ...

  5. django之创建第10-1个项目-图片上传并记录上传时间

    1.百度云盘:django之创建第10-1个项目-图片上传并记录上传时间 2.主要修改的配置文件有3个,forms.views和models3个文件以及html 3.forms.py文件修改 #cod ...

  6. django之创建第10个项目-图片上传方式1

    1.upload.HTMl <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang=& ...

  7. django之创建第9个项目-管理后台admin

    django之创建第9个项目-管理后台admin配置 1.配置setting文件INSTALLED_APPS = (    'django.contrib.auth',    'django.cont ...

  8. django之创建第8-3个项目-数据库数据提取之高级操作

    1.配置test2.html <!DOCTYPE html> <html lang="en"> <head> <meta charset= ...

  9. django之创建第8-1个项目-数据库之增删改查/数据库数据显示在html页面

    1.为test.DB数据库预先创建下面数据 1    张三    16    2015-01-02    12    李四    17    2015-01-04    13    王五    14  ...

随机推荐

  1. 简单绕过Chrome密码查看逻辑,查看浏览器已保存的密码

    简单绕过Chrome密码查看逻辑,查看浏览器已保存的密码   利用场景: 同事或朋友外出有事,电脑未锁屏离开座位.可以利用这一间隙,查看Ta在Chrome浏览器上保存的账号密码 查看逻辑: 当我们要查 ...

  2. ASP.NET MVC 中使用JavaScriptResult asp.net mvc 返回 JavaScript asp.mvc 后台返回js

    return this.Content("<script>alert('暂无!');window.location.href='/Wap/Index';</script&g ...

  3. ArcEngine C++ 10 程序的运行环境,ArcEngine RT的授权

    以前我一直以为 必须安装 Arcgis Desktop才可以授权,发现我错了,原来是这个样子的. 一.安装License manager,并授权许可server.txt 当然这个license也可以安 ...

  4. [leetcode]Max Points on a Line @ Python

    原题地址:https://oj.leetcode.com/problems/max-points-on-a-line/ 题意:Given n points on a 2D plane, find th ...

  5. SQLServer 数据库镜像+复制切换方案

    目标: 主机做了Mirror和Replication,当主机出现问题时,Replication和Mirror实现自动的故障转移(Mirror 和Replication都切换到备机,而当主机 重新启动后 ...

  6. oracle的(+)

    (+)就是连接譬如SELECT a.*, b.* from a(+) = b就是一个右连接,等同于select a.*, b.* from a right join bSELECT a.*, b.* ...

  7. Android -- isInEditMode

    解释 Indicates whether this View is currently in edit mode. A View is usually in edit mode when displa ...

  8. Introduction to Learning to Trade with Reinforcement Learning

    http://www.wildml.com/2015/12/implementing-a-cnn-for-text-classification-in-tensorflow/ The academic ...

  9. 转:使用RNN解决NLP中序列标注问题的通用优化思路

    http://blog.csdn.net/malefactor/article/details/50725480 /* 版权声明:可以任意转载,转载时请标明文章原始出处和作者信息 .*/ author ...

  10. 【转】以太网帧、IP报文格式

    原文:https://www.cnblogs.com/yongren1zu/p/6274460.html https://blog.csdn.net/gufachongyang02/article/d ...