thanks
ANil
Do everything just as you would normally with Django, but when it
comes time to render a template, import and use Cheetah's
template-loading and rendering functions instead of Django's.
--
"May the forces of evil become confused on the way to your house."
-- George Carlin
The Cheetah website gives a simple example of how to produce output from
Cheetah templates ([1]). In Django, you collect the data you want to put
into your output in the normal fashion and then instead of calling
render_to_response() creating a Django template, you create a Cheetah
template and extract the string representation from that, just as in
their example. Then you pass that string to an HttpReponse object in
Django (see [2] and [3], replacing the Django templates with your
Cheetah output instead).
In short, everywhere you would normally pass in the result of rendering
a Django template, you instead pass in the result of rendering a Cheetah
template. You won't be able to use the render_to_response() shortcut,
since that uses the Django template system, but it is only, after all, a
shortcut, so writing your own version that uses Cheetah templates would
be a matter of two or three lines of code.
[1]
http://www.cheetahtemplate.org/docs/users_guide_html_multipage/gettingStarted.tutorial.html
[2]
http://www.djangoproject.com/documentation/tutorial3/#write-views-that-actually-do-something
[3]
http://www.djangoproject.com/documentation/request_response/#httpresponse-objects
Best wishes,
Malcolm
Can you tell me where I can use this in Django or what part of django i
need to use.
As you can see I m fairly a newbie
Thanks
Anil
index.html
1675 def render(template, terms=None, asTemplate=False, base=None,
1676 isString=False):
1677 """
1678 Renders a template, caching where it can.
1679
1680 `template` is the name of a file containing the a template in
1681 the `templates/` folder, unless `isString`, in which case it's
the
1682 template itself.
1683
1684 `terms` is a dictionary used to fill the template. If it's
None, then
1685 the caller's local variables are used instead, plus context,
if it's not
1686 already set, is set to `context`.
1687
1688 If asTemplate is False, it `output`s the template directly.
Otherwise,
1689 it returns the template object.
1690
1691 If the template is a potential base template (that is,
something other templates)
1692 can extend, then base should be a string with the name of the
template. The
1693 template will be cached and made available for future calls to
`render`.
1694
1695 Requires [Cheetah](http://cheetahtemplate.org/).
1696 """
1697 # terms=['var1', 'var2'] means grab those variables
1698 if isinstance(terms, list):
1699 new = {}
1700 old = upvars()
1701 for k in terms:
1702 new[k] = old[k]
1703 terms = new
1704 # default: grab all locals
1705 elif terms is None:
1706 terms = {'context': context, 'ctx':ctx}
1707 terms.update(sys._getframe(1).f_locals)
1708 # terms=d means use d as the searchList
1709 if not isinstance(terms, tuple):
1710 terms = (terms,)
1711
1712 if not isString and template.endswith('.html'):
1713 header('Content-Type','text/html; charset=utf-8',
unique=True)
1714
1715 compiled_tmpl = _compiletemplate(template, base=base,
isString=isString)
1716 compiled_tmpl = compiled_tmpl(searchList=terms,
filter=WebSafe)
1717 if asTemplate:
1718 return compiled_tmpl
1719 else:
1720 return output(str(compiled_tmpl))
That should act as a substitute for Django's Template.render() call. So
wherever you would normally retrieve a Django template and then render
it, you would call this function and pass the result to an HttpResponse
constructor.
> Can you tell me where I can use this in Django or what part of django i
> need to use.
> As you can see I m fairly a newbie
There seems to be a conceptual item you are missing here. You basically
need to achieve two things: (1) produce a string that is a combination
of your template, in whatever format, and your data and (2) send that
string back to the user. You are wanting to do (1) with Cheetah and
HttpResponse and the links I gave you in the previous email show you how
to do (2).
It strikes me you are going about this in a very strange way. I
initially hoped you were wanting to use Cheetah because you were already
very familiar with it. However, if you are not familiar with either
Django or Cheetah then you *must* spend some time learning both. learn
to use Django with the built-in template system for a little bit until
you get used to it. Live and breath the Cheetah manual for a week, or as
long as it takes, until you are familiar with that. Only then, are you
going to be able to merge the two things together.
I don't know why you have chosen not to use Django's templating
language, but you seem to have done so without a lot of experience with
Django itself. So bear in mind that that has now made your job harder
because you now have two new things to learn instead of one. You also
have to work harder to help us help you by doing a lot more experiments
in order to be able to demonstrate and explain the precise problems you
are having.
All that being said, everybody has to start somewhere and sometimes a
big challenge is exactly the motivation a person needs. So if you are
going into this with your eyes wide open, there is no reason it won't
work.
Best wishes,
Malcolm