Re: Can you add a build-in template tags?

2009-10-25 Thread butterhuang

Thank you very much!!

Michael P. Jung wrote:
> > How can I cache the sub-template witch is included in the main
> > template? And how can I ensure it won't be render(parse) the next
> > request?
>
> If you look at django.template.loader_tags.do_include you'll notice an
> if statement that checks if the given argument was a string. If so it'll
> use a ConstantIncludeNode rather than a normal IncludeNode. The constant
> include node inlines the sub-template while the normal node does have to
> look up that variable during render time.
>
> Side notice: That's also the reason why you can't include templates
> recursively with static strings but have to use a workaround like "{%
> with "recursive.html" as template %}{% include template %}{% endwith %}"
> or a custom template tag.
>
>
> Caching the template is as easy as storing the result from get_template
> in a global variable.
>
> e.g.
>
> from django.template.loader import get_template
> foo_template = get_template('foobar.html')
> def foo(request):
> ctx = RequestContext(request)
> ctx.update({'foo': True, 'bar': False})
> return HttpResponse(foo_template.render(ctx))
>
>
> Note: I'd rather lazy load the template in order to decouple things a
> bit. Be aware of race conditions and better synchronize the template
> loading. The above code snippet is only meant to give you the idea.
>
>
> --mp
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en
-~--~~~~--~~--~--~---



Re: Can you add a build-in template tags?

2009-10-20 Thread butterhuang


On 10月19日, 下午4时34分, "Michael P. Jung"  wrote:
> > There is a templatetags {% include 'x.html' %}, it's very nice.  may a
> > templatetags like {% include no-parse "x.html"} is needed. It's so
> > powerful to improve the speed of include some static files which has
> > no variable,and it's so easy for you guys, isn't it?
>
> It'd be very easy to add an template tag that just includes raw data
> from a file. Though I have to comment that this might not be neccesary
> for two reasons:
>
> 1.) The Django templates parse fast and if you're not including an
> extremely large HTML file it should handle it with ease. I've never
> managed to create a CPU bound application, as the database was always
> the slowest part. If you really worry about the template performance so
> much you might be best of switching to some alternative template
> technology like jinja2, which is told to be faster. (*)
>
> 2.) The include tag inlines the included template if it's specified as
> string. So if you cache your template instances and don't regenerate
> them on every request it will get even faster. Only the first request,
> which hasn't cached the template yet will have to parse it once.
>

How can I cache the sub-template witch is included in the main
template? And how can I ensure it won't be render(parse) the next
request?



> (*) Even the jinja2 page states: "Generally speaking the performance of
> a template engine doesn’t matter much as the usual bottleneck in a web
> application is either the database or the application code."
>
> --mp
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en
-~--~~~~--~~--~--~---



Re: Can you add a build-in template tags?

2009-10-18 Thread butterhuang

你好!

pay attention:

SSI ... “which must be specified using an absolute path -- in the
current page

it's not good for migrating.

谢谢!(thanks!)


On 10月19日, 上午1时26分, dc  wrote:
> Please read 
> documentationhttp://docs.djangoproject.com/en/dev/ref/templates/builtins/#ssi

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en
-~--~~~~--~~--~--~---



Can you add a build-in template tags?

2009-10-18 Thread butterhuang


There is a templatetags {% include 'x.html' %}, it's very nice.  may a
templatetags like {% include no-parse "x.html"} is needed. It's so
powerful to improve the speed of include some static files which has
no variable,and it's so easy for you guys, isn't it?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en
-~--~~~~--~~--~--~---