1、模版的执行
模版的创建过程,对于模版,其实就是读取模版(其中嵌套着模版标签),然后将 Model 中获取的数据插入到模版中,最后将信息返回给用户。
1 | def current_datetime(request): |
1 | from django import template |
1 | import datetime |
1 | from django.template.loader import get_template |
1 | return render_to_response('Account/Login.html',data,context_instance=RequestContext(request)) |
2、模版语言
模板中也有自己的语言,该语言可以实现数据展示
1 | {{ item }} |
3、自定义simple_tag
1、在app中创建templatetags模块
2、创建任意 .py 文件,如:xx.py
1 | #!/usr/bin/env python |
3、在settings中配置当前app,不然django无法找到自定义的simple_tag
1 | INSTALLED_APPS = ( |
4、在使用自定义simple_tag的html文件中导入之前创建的 xx.py 文件名
1 | {% load xx %} |
5、使用simple_tag
1 | {% my_simple_time 1 2 3%} |