PhoneGap中文网

 找回密码
 立即注册
查看: 15990|回复: 0
打印 上一主题 下一主题

Django 学习之模板变量

[复制链接]

87

主题

87

帖子

327

积分

中级会员

Rank: 3Rank: 3

积分
327
跳转到指定楼层
楼主
发表于 2017-8-12 14:29:31 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

本文和大家分享的主要是django中模板变量相关内容,一起来看看吧,希望对大家学习django有所帮助。

1.传入普通变量

在hello/Hello World/temlplates/index.html中,修改html文件

<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <title>{{title}}</title>
    <meta charset="utf-8">
</head>
<body>
   <h1> Hello {{name}}</h1>
</body>
</html>
接着在hello/Hello World/views.py文件中,修改views.py

from django.shortcuts import render

def index(request):
    return render(request,'index.html',{'title':'Welcome','name':'KeinLee'})
然%
it营
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

站长推荐 上一条 /1 下一条

ionic4视频教程

Archiver|手机版|小黑屋| PhoneGap中文网 ( 京ICP备13027796号-1 )  

GMT+8, 2024-4-20 03:57 , Processed in 0.038071 second(s), 27 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表