Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

request headers in Django

>>> request.headers
{'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6', ...}

>>> 'User-Agent' in request.headers
True
>>> 'user-agent' in request.headers
True

>>> request.headers['User-Agent']
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6)
>>> request.headers['user-agent']
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6)

>>> request.headers.get('User-Agent')
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6)
>>> request.headers.get('user-agent')
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6)
Comment

django response headers

from django.http import HttpResponse

def index(request):
    response = HttpResponse("Hello world!")
    response["My-Header"] = "header value"
    return response
Comment

add header info in django response

def home_page(request):
    # get the django.http.response.HttpResponse object
    resp = render(request, 'dept_emp/home_page.html')
    # set http response header and value.
    resp['Cache-Control'] = 'public,max-age=100000'
    resp['Vary'] = 'Accept-Encoding'
    # return the HttpResponse object. 
    return resp
Comment

add header info in django response


class MyMiddleware:

    def __init__(self, get_response):
        self.get_response = get_response

    def __call__(self, request):
        response = self.get_response(request)
        response['X-My-Header'] = "my value"
        return response

Comment

PREVIOUS NEXT
Code Example
Python :: print p py pyt pyth pytho python in python 
Python :: python sort columns of pandas dataframe 
Python :: Python program to print all odd numbers in a range 
Python :: convert 1 to "one" python 
Python :: cannot convert float NaN to integer 
Python :: slice dataframe pandas based on condition 
Python :: python slicing multi dimensional array 
Python :: column names pandas 
Python :: check python version 
Python :: np arange 
Python :: to_csv create folder 
Python :: run calc.exe inside python 
Python :: http server in python 
Python :: python functions 
Python :: python list 
Python :: python foreach list 
Python :: discord py fetch channel by id 
Python :: 3d array python numpy 
Python :: python count array length 
Python :: Find the title of a page in python 
Python :: how to remove quotes from a string in python 
Python :: number of column in dataset pandas 
Python :: def function in python 
Python :: Kill python background process 
Python :: python dictionary add key-value pair 
Python :: how to make a multiple choice quiz in python with tkinter 
Python :: pandas change column dtype 
Python :: validity of password in python 
Python :: read json file using python 
Python :: remove all rows with at least one zero pandas 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =