views:

52

answers:

1

the mothed is :

def printa(x):
    return x

the reponse is :

self.response.out.write(template.render(path, {'printa':printa}))

the html is :

{{ printa 'sss'}}

i want to show 'sss' in my page ,

so how to do this ,

thanks

updated

i create a templatetags folder, and 2 py file:

templatetags 
     |--------__init__.py
     |--------tags.py

in tags.py is :

#from django import template
from google.appengine.ext.webapp import template

register = template.Library()

def printa():
    return 'ssss'
register.simple_tag(printa)

the html is :

{% load tags%}
{% printa %}

but it show error,and the error is :

TemplateSyntaxError: 'tags' is not a valid tag library: Could not load template library from django.templatetags.tags, No module named tags

why ?

what's wrong ?

thanks

answer is :

tags.py:

from google.appengine.ext import webapp
register = webapp.template.create_template_register()

@register.filter
def printa(value,y):
return 'url:%s' % y

@register.tag
def printb(x,y):
return str(x.__dict__) +'dddddddddddddddddddddddddddddddd'+ str(y.__dict__)
#return x
#register.tag('printb',do_pagednav)

and then in html (a is a variable i send to the template):

{{a|printa:"dwqdq"}}

{% printb %}

woring:

don't use load :

{% load sometags %}
+1  A: 

Using the default webapp template system (which is actually Django 0.96), you can't do this. You're expected to put the program logic in the program files, not in your templates, so you can't pass arguments to your variables.

You don't say what you're actually trying to do, though; I assume you don't literally want to print something, since you can just put that something in the template without a function and it prints. For whatever you're actually trying to do, registering a custom filter might be what you're looking for.

Wooble
hi Wooble, look the updated
zjm1126
http://javawonders.blogspot.com/2009/01/google-app-engine-templates-and-custom.html has one person's experience with adding filters in webapp; it appears that since you don't have a full django application things are done slightly differently.
Wooble