Ticket #13876: 13876.2.diff
File 13876.2.diff, 1.6 KB (added by , 14 years ago) |
---|
-
docs/ref/request-response.txt
46 46 attr:`~HttpRequest.path` can make your code much easier to move between test 47 47 and deployment servers. 48 48 49 For example, if the ``django.root`` for your application is set to 49 For example, if the ``django.root`` for your application is set to 50 50 ``"/minfo"``, then ``path`` might be ``"/minfo/music/bands/the_beatles/"`` 51 51 and ``path_info`` would be ``"/music/bands/the_beatles/"``. 52 52 … … 420 420 >>> response.write("<p>Here's the text of the Web page.</p>") 421 421 >>> response.write("<p>Here's another paragraph.</p>") 422 422 423 You can add and delete headers using dictionary syntax::424 425 >>> response = HttpResponse()426 >>> response['X-DJANGO'] = "It's the best."427 >>> del response['X-PHP']428 >>> response['X-DJANGO']429 "It's the best."430 431 Note that ``del`` doesn't raise ``KeyError`` if the header doesn't exist.432 433 423 Passing iterators 434 424 ~~~~~~~~~~~~~~~~~ 435 425 … … 444 434 Setting headers 445 435 ~~~~~~~~~~~~~~~ 446 436 447 To set a header in your response, justtreat it like a dictionary::437 To set or remove a header in your response, treat it like a dictionary:: 448 438 449 439 >>> response = HttpResponse() 450 440 >>> response['Cache-Control'] = 'no-cache' 441 >>> del response['Cache-Control'] 451 442 443 Note that unlike a dictionary, ``del`` doesn't raise ``KeyError`` if the header 444 doesn't exist. 445 452 446 .. versionadded:: 1.1 453 447 454 448 HTTP headers cannot contain newlines. An attempt to set a header containing a