Setting mimetypes is normally done with cherrypy.response.headers.
import cherrypy def hello(self): cherrypy.response.headers['Content-Type']= 'text/xml' return "<hello world />"
CherryPy 3 has a builtin Tool for this purpose:
@cherrypy.tools.response_headers([('Content-Type', 'text/xml')]) def hello(self): return "<hello world />"
But if you like you can do it with custom decorators too:
import cherrypy def mimetype(type): def decorate(func): def wrapper(*args, **kwargs): cherrypy.response.headers['Content-Type'] = type return func(*args, **kwargs) return wrapper return decorate class MyClass: @mimetype("text/xml") def hello(self): return "<helloWorld />"
Older versions
| replace this | with this | |
| 2.1 | headers | headerMap |
| 2.0 | import cherrypy | from cherrypy import cpg as cherrypy |

