开发者

Python replacement for PHP's header

开发者 https://www.devze.com 2023-01-20 14:27 出处:网络
How to send a raw http header in python just like header() in开发者_运维问答 PHP ?In Django, you\'d be like:

How to send a raw http header in python just like header() in开发者_运维问答 PHP ?


In Django, you'd be like:

def someview(request):
    # ... etc ...
    out = HttpResponse(outputstring,
        mimetype="text/html",
        status_code="302",
        )
    out['Content-Disposition'] = "attachment; filename=download.html"
    # fill in all your favorite HTTP headers here
    return out

... for cache-control and friends, you need to import a bunch of decorators and wrap your view functions accordingly (I forget which) -- this is because django has a caching system with which many sub-rosa bits of the framework are integrated.

I find the cache stuff confusing, but also nice. non-cache HTTP headers are E-Z.


Pass a list of two-tuples containing the header name and header value to the start_response() function.

0

精彩评论

暂无评论...
验证码 换一张
取 消