Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Send Post Fetch REquest With Django

function getCookie(name) {
        let cookieValue = null;
        if (document.cookie && document.cookie !== '') {
            const cookies = document.cookie.split(';');
            for (let i = 0; i < cookies.length; i++) {
                const cookie = cookies[i].trim();
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) === (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
    const csrftoken = getCookie('csrftoken');

async    function send()
  {
let r =      await fetch('/blog/third', {method: 'POST', 
                                         credentials: 'same-origin',
                                         headers:{'Accept': 'application/json',   
                                         'X-Requested-With': 'XMLHttpRequest', 
                                         'X-CSRFToken': csrftoken}
                                        });
let res = await r.json();
console.log(res.text);
    }
    
#as you can see, it's much more complicated than GET :)
#but in reality this is probably what you will end up doing
Comment

Send Fetch Request Django(Get Method)

async    function send()
    {

let r =      await   fetch('/blog/third', {method: "GET"});
let res = await r.json();
console.log(res.text);

    }
Comment

PREVIOUS NEXT
Code Example
Python :: python selenium console log 
Python :: image data generator keras with tf.data.Data.from_generator 
Python :: how to find highest number in list python 
Python :: is python easy or hard to learn 
Python :: seaborn countplot hue stacked 
Python :: django change foreign key 
Python :: max python 
Python :: python if file exists append else create 
Python :: python equivalent of R sample function 
Python :: python edit item in list 
Python :: filter field set in django formds 
Python :: semicolon python 
Python :: how should i learn python 
Python :: convert pandas data frame to latex file 
Python :: python pass arguments in command line 
Python :: parse_dates 
Python :: numpy maximum 
Python :: export postgres database to heroku 
Python :: np.all 
Python :: pandas order dataframe by column of other dataframe 
Python :: putting in text in python 
Python :: how to create a User and User profile in django rest framework 
Python :: python gui framework 
Python :: default python packages 
Python :: post from postman and receive in python 
Python :: class __call__ method python 
Python :: python strip() 
Python :: convert method to str python 
Python :: quicksort algorithm in python 
Python :: python regex (d)(?=d1) 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =