CherryPy Project Download

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:[('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:
    def hello(self):
        return "<helloWorld />"

Older versions

replace this with this
2.0import cherrypyfrom cherrypy import cpg as cherrypy

Hosted by WebFaction

Log in as guest/cherrypy to create/edit wiki pages