I'm building a React application for a Django backend. In the backend the security setting CSRF_TOKEN_HTTPONLY is set to True. How can I obtain this csrf token in a React app? The documentation only describes how to do that using jquery. I'm usin the fetch API for my http requests.
React: How to get a Django CSRF Token if CSRF_TOKEN_HTTPONLY is true?
405 Views Asked by J. Hesters At
1
There are 1 best solutions below
Related Questions in DJANGO
- Display images on Django Template Site
- Protractor did not run properly when using browser.wait, msg: "Wait timed out after XXXms"
- Django invalid literal for int() with base 10:
- Removing URL features from tokens in NLTK
- Django Noob URL to from Root Page to sub Page
- Django Admin tables not displaying correctly
- Django with chartkick
- Django urls.py not rendering correct template
- django form errors before submit
- django admin: custom app_index with context
- Display multiple models in one view in Django
- Unexpected NoReverseMatch error when using include() in urls patterns
- Search for a key in django.core.cache
- Django webapp (on an Apache2 server) hangs indefintely when importing nltk in views.py
- Django flush won't load fixtures
Related Questions in REACTJS
- What is `_dereq_()` inside React?
- React TypeError: React.renderComponent is not a function
- React - saving a component in the ref callback
- React Rails component: manually triggering a re-render
- React, ES6 - getInitialState was defined on a plain JavaScript class
- How to get multiple selected options value in React JS?
- React.render replace container instead of inserting into
- reactjs datagrid use html
- props is not initialized in react component
- How to display xml data using Reactjs
- hooking up the data model in ReactJS - syntax
- ReactJS: How to use an immutable empty array or object
- How to use Sinon.js FakeXMLHttpRequest with superagent?
- React select onChange is not working
- ReactJS - Tutorial Comment System > Threaded commenting
Related Questions in FETCH
- How to figure out the optimal fetch size for the select query
- How to call ".done" after the ajax call in Backbone fetch calls
- SELECT * FROM WHERE Query isn't retrieving any results
- Retrieving data using a pointer in Parse.com
- How to connect from your iOS app to a backend server? how to read, modify and fetch data to backend server?
- Does sparse checkout affect git fetch?
- Fatal error which fetching data from mysqli with limit
- Make Branch accessible after git fetch
- PDO fetch and fetchAll with conditional statement not working
- Backbone.js collection fetch not setting response objects as models
- How to use OFFSET and Fetch without Order by in SQL Server
- Fetching data before rendering server side
- PHP DBH->fetch() and fetchAll(), there is a way to get rid of "numbered" items in the returned arrays?
- $GET query to directory?
- Why this code does not fetch query as I expect?
Related Questions in DJANGO-CSRF
- Django CSRF cookie not set error if there is cookie value starting with square brackets '['
- Django Rest Framework remove csrf
- CSRF token not getting inserted into template
- Django: "Forbidden (403) CSRF verification failed. Request aborted." in Docker Production
- @csrf_exempt not working for rest api
- How can I check csrf-cookie while processing GET request?
- Django CSRF_COOKIE_DOMAIN - how to change gracefully
- Django : How to override the CSRF_FAILURE_TEMPLATE
- Unauthorized CSRF validation failed in jMeter testing
- Django Rest Framework - DELETE ajax call failure due to incorrect CSFR token
- Clould9's Django out of the box: Admin page CSRF :443 error
- Django csrf token invalid after modifying request
- CSRF Django, ValueError
- Template-less Django + AJAX: Does Django's CSRF token get updated during the course of a browsing session?
- django not rendering csrf_token cant see why
Related Questions in DJANGO-2.1
- django2.1,Use mysql to custom login,MySQL: "Field 'id' doesn't have a default value"
- django parameter causing the wrong template and view to render
- 'WSGIRequest' object has no attribute 'is_authenticated'
- Putting username of logged in user as label in django form field
- Django not serving static files in deployment server
- Having trouble using PostgreSQL database with Django and Windows 10
- Multiple querystring parameters
- Exclude a type of post from pagination
- Incorrect redirection for a single post category
- Django sitemap.xml throwing Server Error (500) in production
- How to manage a dynamic menu with Django?
- Urls with Categories slug and Post slug using Class Based View
- React: How to get a Django CSRF Token if CSRF_TOKEN_HTTPONLY is true?
- regular expression not recognized by django
- Change url in Django
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
If you include the csrf token in your HTML like the documentation says:
Then you can simply get the token like this:
And do your requests with the Fetch API this way: