How do I use Django's MarkUp Templates Tags with Google App Engine WebApp Framework
I'm using Google App Engine WebApp Framework which works with Django's Templates. I'm trying to use Django's MarkUp filters and the instructions say:
- Put django.contrib.markup in your INSTALLED_APPS
- Load markup in your templates via {% load markup %}
- Filter whatever text with the appropriate filter: {{ text|textile }}
My question is since I'm using the webapp fram开发者_JAVA技巧ework I don't have a "INSTALLED_APP" middleware. Does anyone know how I can load this module in webapp?
Set up tag library:
Create a folder in your app directory, customtags
for example.
Within this folder create an empty __init__.py
file
in the same folder create your tags file customtags.py
for example
At the beginning of 'customtags.py' add the following lines
from google.appengine.ext import webapp
register = webapp.template.create_template_register()
Add your new tag library to your main.py file like so:
template.register_template_library('customtags.customtags')
Assuming you already have:
from google.appengine.ext.webapp import template
Create your tags like so:
Filter tag:
@register.filter
def foobar(value):
return value
call from template like so:
{{ something|foobar }}
Simple tag:
@register.simple_tag
def mysimpletag():
print 'hello from the simple tag'
call from template like so:
{% mysimpletag %}
Inclusion tag:
@register.inclusion_tag('templates/menu.html')
def menu():
items = db.GqlQuery('SELECT * FROM Pages')
return {'items':items}
call from templte like so:
{% menu %}
精彩评论