Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

csrf token fetch django

let data = {
    'file': file,
    'fileName': file.name,
};
// You have to download 3rd Cookies library
// https://docs.djangoproject.com/en/dev/ref/csrf/#ajax
let csrftoken = Cookies.get('csrftoken');
let response = fetch("/upload/", {
    method: 'POST',
    body: JSON.stringify(data),
    headers: { "X-CSRFToken": csrftoken },
})
Comment

csrf token django

Cross Site Request Forgery protection¶
The CSRF middleware and template tag provides easy-to-use protection against
Cross Site Request Forgeries. This type of attack occurs when a malicious
website contains a link, a form button or some JavaScript that is intended 
to perform some action on your website, using the credentials of a logged-in 
user who visits the malicious site in their browser. A related type of attack,
‘login CSRF’, where an attacking site tricks a user’s browser into logging into
a site with someone else’s credentials, is also covered.

The first defense against CSRF attacks is to ensure that GET requests
(and other ‘safe’ methods, as defined by RFC 7231#section-4.2.1) are
 side effect free. Requests via ‘unsafe’ methods, such as POST, PUT,
 and DELETE, can then be protected by following the steps below.
Comment

PREVIOUS NEXT
Code Example
Python :: impute mode pandas 
Python :: how to rotate image in pygame 
Python :: how to read xlsx file in jupyter notebook 
Python :: read specific rows from csv in python 
Python :: python how to find gcd 
Python :: python open file relative to script location 
Python :: random sample with weights python 
Python :: imblearn randomoversampler 
Python :: plotly hide color bar 
Python :: discord python webhook 
Python :: logistic regression algorithm in python 
Python :: failed to allocate bitmap 
Python :: how to find the location of a character in a string in python 
Python :: jaccard distance python 
Python :: write a list into csv python 
Python :: godot setget 
Python :: how to create a label in python 
Python :: what does class meta do in django 
Python :: print list in reverse order python 
Python :: create exe from python script 
Python :: calculate age python 
Python :: remove extra spaces python 
Python :: python dictionary to array 
Python :: object literal python 
Python :: how can item in list change in int in python 
Python :: get dictionary elements by index in python 
Python :: python pandas apply function to one column 
Python :: clamp number in python 
Python :: list to string 
Python :: axios django 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =