In gmane.comp.web.pylons.general, you wrote:
>
> 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>'
>
Don't you think an html renderer should go in the core of pyramid ?
It will be fine for one-file or any short pyramid app.
Maybe even, returning a string without any renderer could use this since
it's already the default when we use Response (when we look at
trypyramid.com, html content type is not explicit).
--
William
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pylons-discuss.
For more options, visit https://groups.google.com/d/optout.