Wow...okay that does work!
Here's what's happening...
Your example works----
This also works:
@expose(content_type='text/plain')
def show_text_file(self, **kw):
requested = kw['file']
f = open(requested)
data = f.readlines()
f.close()
return "".join(data[-500:])
This however doesn't work, it gives it as html:
@expose(content_type='text/plain')
def show_text_file(self, **kw):
requested = kw['file']
f = open(requested)
data = f.readlines()
f.close()
return data[-500:]
But this weirdly does work, it's returned as text
@expose()
def show_text_file(self, **kw):
requested = kw['file']
f = open(requested)
data = f.readlines()
f.close()
cherrypy.response.headers['Content-Type'] = "text/plain"
return data[-500:]
I expected the exact same behavior setting the content_type in the
expose or using the response headers, but you get different results
depending on what you return.
Strange...but I assume this is the expected behavior. (Maybe it would
be better to raise an exception if a string is not returned when you
set the content-type to 'text/plain' instead of ignoring the content-
type parameter in this case?)
On Jan 22, 1:00 pm, Christoph Zwerschke <[email protected]> wrote:
> [email protected] schrieb:
>
> > What I can't understand is from what I can tell from the docs, instead
> > of the cherrypy.response line I should be able to do
> > @expose(content_type='text/plain') but that doesn't work. It just
> > sends it as text/html anyway.
>
> Sure? The following worked for me with TG 1.0.8:
>
> �...@expose(content_type='text/plain')
> def show_text(self):
> return 'This is plain text'
>
> -- Christoph
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---