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 :: roc curve 
Python :: Converting 12 hour clock time to 24 hour clock time 
Python :: python how to restart thread 
Python :: Python NumPy delete Function Example Deletion from 1D array 
Python :: NumPy invert Syntax 
Python :: aws python sdk 
Python :: clear 
Python :: how to import somthing from another directory in pyhon 
Python :: python iterating through a list 
Python :: how to access pandas column 
Python :: pandas save dataframe with list 
Python :: Find the path of python executable 
Python :: python 2d array 
Python :: cool python imports 
Python :: python keyword arguments 
Python :: add all elements of list to set python 
Python :: how to get the time zones in python 
Python :: how to append to a string in python 
Python :: input() function in python 
Python :: date and time using tkinter 
Python :: what is self 
Python :: return more than one value python 
Python :: doing some math in python 
Python :: python decorator class 
Python :: python size of list 
Python :: python print font size 
Python :: queryset django 
Python :: Show column names and indexes dataframe python 
Python :: web3.py failing not installing 
Python :: Class 10: Conditional Statements in Python [IF, ELIF, ELSE] 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =