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 :: random 0 or 1 python 
Python :: change marker border color plotly 
Python :: calculate mean median mode in python 
Python :: turn off warning when import python 
Python :: uninstall python using powershell 
Python :: python random randint string 
Python :: difference between set and tuple in python 
Python :: python make file executable 
Python :: python turtle triangle 
Python :: pyplot savefig 
Python :: how to update sklearn 
Python :: create pandas dataframe from dictionary 
Python :: roman to integer 
Python :: sort a dictionary 
Python :: column to int pandas 
Python :: joining two lists in python 
Python :: tkinter button 
Python :: python print value and variable name 
Python :: python subtract every element in list 
Python :: python to executable windows 
Python :: with open as file python 
Python :: seir model python 
Python :: python subtract list from list 
Python :: django-sslserver 
Python :: creating a sqlite3 table in python and inserting data in it 
Python :: python formdata requests 
Python :: cors flask 
Python :: How to take space-separated integer input in Python 3 
Python :: discord.py find voice channel by name 
Python :: python get desktop environment 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =