Python replacement for PHP's header
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.
精彩评论