On 03/13/2015 04:05 PM, Jonathan Vanasco wrote:
On Friday, March 13, 2015 at 3:53:38 PM UTC-4, Chris McDonough wrote:
You mean renderers specified via view_config(renderer=...). Like I
said, I don't think this is the right place to implement caching.
Sorry, I think we're having 2 different conversations about the same thing.
s/about the same thing// but ok ;)
I'm not suggesting that caching be implemented in
`view_config(renderer=...)`.
I'm just stating that `view_config(renderer=...)` natively supports
"renderers" that are templating engines, json, raw strings (as
"text/plaintext"), but not actually HTML. Where the HTML comes from is
irrelevant (be it a cache or manually created during the view). In
order to return HTML from a view, one needs to manually craft a
response. That is what I find awkward.
OK that's a different issue, yep. It would be great if you could
currently do this:
@view_config(renderer='string')
def myview(request):
request.response.content_type = 'text/html'
return '<html><body>Hi</body></body>'
But you can't. It's a bit of a genuine bug that you can't due to the
way the string renderer operates, but I've never figured out a good way
to fix it. You can work around it currently by doing something like this:
@view_config(renderer='string')
def myview(request):
request.response.content_type = 'text/html '
return '<html><body>Hi</body></body>'
Note the space after text/html inside the string literal assigned to
response.content_type. Yes, lame, I know. You'll see why its necessary
if you read the string renderer code.
Of course you can also make a custom renderer:
from pyramid.compat import string_types
def html_renderer_factory(info):
def _render(value, system):
if not isinstance(value, string_types):
value = str(value)
return value
return _render
config.add_renderer('html', html_renderer_factory)
Then:
@view_config(renderer='html')
def myview(request):
return '<html><body>Hi</body></body>'
What this has to do with caching or the other conversation I have no
idea, but there it is.
- C
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to pylons-discuss+unsubscr...@googlegroups.com.
To post to this group, send email to pylons-discuss@googlegroups.com.
Visit this group at http://groups.google.com/group/pylons-discuss.
For more options, visit https://groups.google.com/d/optout.