Skip to content
Browse files

fixed formatting of python code for testing template rendering

currently, it's showing up without linefeeds on webpy.org
I fixed it so it looks like what I think is correct
I'm using gedit with "replace tabs with spaces", so I'm not sure
why my previous commit had messed-up tabs/spaces. Let me know how
to do it better for next time.
  • Loading branch information...
1 parent 8f33e02 commit 9329f0c9deb9342dfcf1415efac1a7d102493db8 @stevekochscience committed Aug 1, 2012
Showing with 8 additions and 4 deletions.
  1. +8 −4 template_tricks.md
View
12 template_tricks.md
@@ -10,17 +10,21 @@ title: template tricks
Test the rendering of a template.py template
def renderTemplate(templatename,*args,**kw):
- '''quick way to test a template.py template''' import template
+ '''quick way to test a template.py template'''
+ import template
if not "." in templatename:
- templatename = templatename + ".tmpl" obj = template.Template(open(templatename).read())
+ templatename = templatename + ".tmpl"
+ obj = template.Template(open(templatename).read())
return obj(*args,**kw)
print renderTemplate("homepage", now=time.ctime())
If your template takes a dict or a storage, then you can just
set global values and let those get passed in:
- username = "User" lastvisit = "yesterday" print renderTemplate("results", store=web.Storage(globals()))
+ username = "User"
+ lastvisit = "yesterday"
+ print renderTemplate("results", store=web.Storage(globals()))
---
@@ -54,4 +58,4 @@ you forget the space, you'll get this error from template.py:
myElement = $$('elementID');
----
+---

0 comments on commit 9329f0c

Please sign in to comment.
Something went wrong with that request. Please try again.