您当前的位置: 首页 >  django

暂无认证

  • 6浏览

    0关注

    92582博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Django-Templates模板语法(一)

发布时间:2020-12-05 15:53:57 ,浏览量:6

模版语法传值
{{}}:变量相关
{%%}:逻辑相关

urls.py

urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^index',views.index), ] 

views.py

def index(request): # 模版语法可以传递的后端python数据类型 n = 123 f = 11.11 s = '我也想奔现' b = True l = ['小红','姗姗','花花','茹茹'] t = (111,222,333,444) d = {'username':'jason','age':18,'info':'这个人有点意思','hobby':[111,222,333,{'info':'NB'}]} se = {'晶晶','洋洋','嘤嘤'} lll = [] def func(): print('我被执行了') return '你的另一半在等你' class MyClass(object): def get_self(self): return 'self' @staticmethod def get_func(): return 'func' @classmethod def get_class(cls): return 'cls' # 对象被展示到html页面上 就类似于执行了打印操作也会触发__str__方法 def __str__(self): return '到底会不会?' obj = MyClass() # return render(request,'index.html',{})  # 一个个传 return render(request,'index.html',locals()) 

index.html

<p>{{ n }}{ f }}{ s }}{ b }}{ l }}{ d }}{ t }}{ se  }}{ func }}{ MyClass }}{ obj }}{ obj.get_self }}{ obj.get_func }}{ obj.get_class }}{ d.username }}{ l.0 }}{ d.hobby.3.info }}            
关注
打赏
1653961664
查看更多评论
立即登录/注册

微信扫码登录

0.6798s