title: How to retrieve data from self-made restfull_api
body: <p>I trying to retrieve the information from my API via Y/views.py from another app in the same project. I am receiving the following error ([WinError 10061]). Although, i am able to perform get/post/put via my json_main.js. Thanks to all who support me in this journey. Please read what is already working. And as additional question I would ask why it is not possible to retrieve the data directly via my model/sqlite db.</p>
  
  <p>I already created the following:
  X/Views + X/Template.html. X/Views renders information from the backend to the X/template.html. Within this template there is a JSON script(working) that performs a POST/GET/PUT to the API(working) on image click.</p>
  
  <p>The function ultimately results in a new record in API/Bestellingen. The information stored via this JSON function (incl. token authentication; csrf) should now be retrieved in the views.py of Y/view. I already created an example dict. that is rendered to Y/template.html</p>
  
  <p>I tried several JSON request methods (coreapi, urllib2, urllib3, requests), but keep receiving the error as mentioned before. As already stated: JSON.js script does work. Doing the same via POSTMAN also works.</p>
  
  <p>Since i am performing the same via .js and postman, I am quite sure that the variables (token, header and the request) should be ok. </p>
  
  <p>I will show some short snippets of already working code. Herafter i will show the code that doesn't seem to work.</p>
  
  <p>Information from X/views.py -> X/template.html</p>
  
  <pre><code>return render(request, 'smaakjes/smaakjes.html', {'Drank': super_dict})
  </code></pre>
  
  <p>X/Template.html (see onclick ="")</p>
  
  <pre><code>{% for key, value_list in Drank.items %}
  &lt;img onclick="PostImageDetails(this)" style="margin: 0 auto;" src="{{   value }}" id="{{ value }}"&gt;
  </code></pre>
  
  <p>JSON.js (works), sends information to http:127:0:0:0:8000/api/bestellingen. I can see the stored information via the API view. </p>
  
  <pre><code>xmlhttp.send(JSON.stringify({'url':imageSrc, 'username': imageId}))
  </code></pre>
  
  <p>Y/views.py -> renders information to Y/template.html(works)</p>
  
  <pre><code>def BestellingenDashboard(request):
  
  Data = {'iets': '1'}
  return render(request, 'homepage.html', {'bestellingen' : Data})
  </code></pre>
  
  <p>Once information has been stored in the API/bestellingen, I would like to retrieve the whole json dict. via python Y/Views.py and store it in the above 'Data'(that's ofc easy :)). Does somebody know what i am doing wrong? Why is postman working? Am i Missing a header or something? In my opinion, retrieving data from your own API should be very easy :D</p>
  
  <pre><code>from django.http import HttpResponse
  from django.shortcuts import render
  from api.models import Bestellingen
  import json
  import secrets
  import requests
  
  URL = "http://127.0.0.1:8000/api/bestellingen/"
  data_json = json.dumps(data)
  payload = {'json_payload': data_json}
  
  r = requests.get(url=URL, headers={'Content-Type': 'application/json', 'token' : secrets.token_hex(40)}, json=payload)
  a = r.json()
  print(a)
  
  def BestellingenDashboard(request):
  
      Data = {'iets': '1'}
      return render(request, 'homepage.html', {'bestellingen' : Data})
  </code></pre>
  
  <p>As you can read, most is working (api, endpoints, apiviews, rendering info from X-X.html,X.html->API. I now want to get the information in Y.views, so that i can use this information in Y/template.html</p>