The Django template language 阅读批注】的更多相关文章

The Django template language About this document This document explains the language syntax of the Django template system. If you’re looking for a more technical perspective on how it works and how to extend it, see The Django template language: For…
一.标签 tags 1.普通变量 普通变量用{{ }} 变量名由数字.字母.下划线组成 点.在模板语言中用来获取对象相应的属性值 示例 {# 取variable中的第一个参数 #} {{ variable.0 }} {# 取字典dic中key的值 #} {{ dic.key }} {# 取obj_list对象列表中第一个对象的attr属性值 #} {{ obj_list.0.attr }} {# 点操作只能调用不带参数的方法 #} {{ obj_list.0.method }} 1 2 3 4…
Django文档阅读-Day1 Django at a glance Design your model from djano.db import models #数据库操作API位置 class Reporter(models.Model): full_name = models.CharField(max_length=70) #print(obj)时输出对象的full_name def __str__(self): return self.full_name class Article(m…
Django文档阅读-Day3 Writing your first Django app, part 3 Overview A view is a "type" of Web page in your Django application that generally serves a specific function and has a specific template. For example, in a blog application, you might have th…
一.模板基本元素 1.例子程序 1)urls.py中新增部分 from django.conf.urls import patterns, url, include urlpatterns = patterns('', #... (r'^template_use/$', 'django_web_app.views.template_use'), ) 2)views.py中新增部分 def template_use(request): person_name='jimfeng' company='…
前面的章节我们看到如何在视图中返回HTML,但是HTML是硬编码在Python代码中的 这会导致几个问题: 1,显然,任何页面的改动会牵扯到Python代码的改动 网站的设计改动会比Python代码改动更频繁,所以如果我们将两者分离开会更方便 2,其次,写后台Python代码与设计HTML是不同的工作,更专业的Web开发应该将两者分开 页面设计者和HTML/CSS程序员不应该编辑Python代码,他们应该与HTML打交道 3,程序员写Python代码同时页面设计者写HTML模板会更高效,而不是一…
模板的作用方法有如下三种: blog/views.py: from django.template import loader, Context, Template from django.http import HttpResponse from django.shortcuts import render_to_response as r2r def index(req): t = loader.get_template('index.html') c = Context({'uname':…
本节介绍模板中的内置标签:if for 承上文,修改 views.py 如下: from django.shortcuts import render_to_response class Person(object): def __init__(self, name, age, sex): self.name = name self.age = age self.sex = sex def say(self): return "This is " + self.name def ind…
模板变量用双大括号显示,如: <title>page title: {{title}}</title> 一 模板中使用变量 继续前面的例子,修改 index.html: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html x…
Django Template 你可能已经注意到我们在例子视图中返回文本的方式有点特别. 也就是说,HTML被直接硬编码在 Python 代码之中. 下面我们来调用html views def index(request,user): if request.method == 'GET': user_info = { 'username':'alex', 'name':'Alex Li' } return render(request,'app01/index.html',{'user_obj'…