title: Django - taking values from POST request, JavaScript fetch API
body: <p>Sorry if this is a noob question, I am  creating a <strong>Django app</strong> and for that I am trying to access data received from POST request, using JavaScript fetch API but it is showing empty .
  I can't get what my mistake is.
  I have tried to remove all unnecessary parts to debug.The error is in this part:</p>
  <p>Code of my <code>views.py</code></p>
  <pre><code>def checkdb(request):
      if request.method == &quot;POST&quot;:
          a = request.POST.get('tag', 'default')
          print(&quot;printing&quot;, a)
          print(request.POST)
      return HttpResponse(&quot;Hello&quot;)
  
  def check(request):
      return render(request, 'shop/new.html')
  </code></pre>
  <p>Code of <code>URLS.py</code></p>
  <pre><code>urlpatterns = [
      path('', views.index, name=&quot;shop&quot;),
      path('checkdb/', views.checkdb, name=&quot;checkdb&quot;),
      path('check/', views.check, name=&quot;check&quot;),
  ]
  </code></pre>
  <p>Code of <code>new.html</code>, it has only script tag to fetch request just for testing purpose.</p>
  <pre><code>&lt;script&gt;
  
  data = JSON.stringify({
      headline: &quot;Testing&quot;,
      tag: &quot;Testing&quot;,
      background_image: &quot;Testing&quot;,
      content: &quot;Testing&quot;,
      user: 1
  })
  
  let csrftoken = getCookie('csrftoken');
  let response = fetch(&quot;/shop/checkdb/&quot;, {
      method: 'POST',
      body: data,
      headers: { 'Accept': 'application/json, text/plain, */*',
          'Content-Type': 'application/json',
          &quot;X-CSRFToken&quot;: csrftoken },
  })
  
  
  function getCookie(name) {
      var cookieValue = null;
      if (document.cookie &amp;&amp; document.cookie !== '') {
          var cookies = document.cookie.split(';');
          for (var i = 0; i &lt; cookies.length; i++) {
              var cookie = cookies[i].trim();
              if (cookie.substring(0, name.length + 1) === (name + '=')) {
                  cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                  break;
              }
          }
      }
      return cookieValue;
  }
  
  &lt;/script&gt;
  </code></pre>
  <p>When i go to endpoint <em>shop/check</em>  then its script tag executes and there is no error in console but when i try to print the data received in terminal then it always prints default option i am not getting what is mistake I want to print the data corresponding to key &quot;tag&quot; which is &quot;Testing&quot; but it is giving default option Please help me to find out my mistake.</p>
  <p>OUTPUT in terminal</p>
  <pre><code>Quit the server with CTRL-BREAK.
  [01/May/2020 19:09:02] &quot;GET /shop/check/ HTTP/1.1&quot; 200 1091
  printing default
  &lt;QueryDict: {}&gt;
  [01/May/2020 19:09:02] &quot;POST /shop/checkdb/ HTTP/1.1&quot; 200 5
  </code></pre>
  <p>I am using Django 3.0.4.</p>
  <p>Thanks and sorry if there is any silly mistake, i am a newbie in Django</p>