如何在django中使用mako模板系统
2013-02-03 11:38
746 查看
如何在django中使用mako模板系统
2009-03-26 23:39
1、安装mako:
下载地址:http://www.makotemplates.org/download.html
2、安装Django-mako
下载地址:http://pypi.python.org/pypi/django-mako
参考网址:http://code.google.com/p/django-mako/wiki/Usage
Installinghttp://pypi.python.org/pypi/django-mako.
Django-mako is a normal Python package. If you have setuptools installed you can use easy_install.
$ easy_install django-mako
You can also download the tarball from PyPI,
Then extract it and run setup.py install.
$ tar -zxf django-mako-0.1.0.tar.gz
$ sudo python setup.py install
Once installed, the main module name is djangomako.
EnablingShortcutsUsing djangomako in your views
You enable django-mako like any other Django middleware, by adding a single entry to your MIDDLEWARE_CLASSES tuple in your settings.py.
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'djangomako.middleware.MakoMiddleware',
)
django-mako will also look for a MAKO_TEMPLATE_DIRS setting, if it's not set than mako will use the same TEMPLATE_DIRSsetting which is also used by the django templating system. This gives you the option of separating your mako templates from your django templates
or simply keeping all your templates together.
django-mako provides shortcut functions that mimic django templates render_to_string and render_to_response.
Note: These functions to not support context instances... mostly because I don't really understand what they are suppose to be used for.
from djangomako.shortcuts import render_to_response, render_to_string
def index_view(request):
return render_to_response('index.html', {'user':request.user})
def print_index_view(request):
print render_to_string('index.html', {'user':request.user})
3、中文模板处理
参考网址:http://limodou.javaeye.com/blog/90860
在模板顶部加上编码
#coding=utf-8 或者 ## -*- coding: utf-8 -*-
2009-03-26 23:39
1、安装mako:
下载地址:http://www.makotemplates.org/download.html
2、安装Django-mako
下载地址:http://pypi.python.org/pypi/django-mako
参考网址:http://code.google.com/p/django-mako/wiki/Usage
Installinghttp://pypi.python.org/pypi/django-mako.
Django-mako is a normal Python package. If you have setuptools installed you can use easy_install.
$ easy_install django-mako
You can also download the tarball from PyPI,
Then extract it and run setup.py install.
$ tar -zxf django-mako-0.1.0.tar.gz
$ sudo python setup.py install
Once installed, the main module name is djangomako.
EnablingShortcutsUsing djangomako in your views
You enable django-mako like any other Django middleware, by adding a single entry to your MIDDLEWARE_CLASSES tuple in your settings.py.
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'djangomako.middleware.MakoMiddleware',
)
django-mako will also look for a MAKO_TEMPLATE_DIRS setting, if it's not set than mako will use the same TEMPLATE_DIRSsetting which is also used by the django templating system. This gives you the option of separating your mako templates from your django templates
or simply keeping all your templates together.
django-mako provides shortcut functions that mimic django templates render_to_string and render_to_response.
Note: These functions to not support context instances... mostly because I don't really understand what they are suppose to be used for.
from djangomako.shortcuts import render_to_response, render_to_string
def index_view(request):
return render_to_response('index.html', {'user':request.user})
def print_index_view(request):
print render_to_string('index.html', {'user':request.user})
3、中文模板处理
参考网址:http://limodou.javaeye.com/blog/90860
在模板顶部加上编码
#coding=utf-8 或者 ## -*- coding: utf-8 -*-
相关文章推荐
- 如何在单独使用django的模板系统
- [Django模板系统]如何使用Django模板系统
- PYTHON(DJANGO)使用日记之如何找到linux系统下django的安装路径
- Django模板template(html)中如何使用注释comment,单行注释,多行注释:
- 如何在django使用多说评论系统
- Mako 模板系统文档翻译(1) 使用基础
- Mako 模板系统文档翻译(1) 使用基础
- The Definitive Guide To Django 2 学习笔记(六) 第四章 模板 (二)使用模板系统
- [Django 1.5] jQuery/Ajax 在Django使用 ,如何更新模板里里变量
- 在Django中使用Mako模板
- [Django模板系统]在视图中使用模板
- python如何直接在命令行使用系统模板template
- Django模板中如何导入js、css等外部文件
- django 1.8 官方文档翻译: 13-9-1 如何使用会话
- Django DTL 模板系统的局限与理念
- Django 模板(Template)系统
- Django 模板中变量、过滤器、标签的使用方法
- 如何使用grub硬盘安装fedora和ubuntu两个主流linux系统
- Django项目中如何在模板文件中加载静态文件
- 如何使用Word系统撰写和排版毕业论文