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.

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.

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

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.

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.

I will show some short snippets of already working code. Herafter i will show the code that doesn't seem to work.

Information from X/views.py -> X/template.html

return render(request, 'smaakjes/smaakjes.html', {'Drank': super_dict})

X/Template.html (see onclick ="")

{% for key, value_list in Drank.items %}
<img onclick="PostImageDetails(this)" style="margin: 0 auto;" src="{{   value }}" id="{{ value }}">

JSON.js (works), sends information to http:127:0:0:0:8000/api/bestellingen. I can see the stored information via the API view.

xmlhttp.send(JSON.stringify({'url':imageSrc, 'username': imageId}))

Y/views.py -> renders information to Y/template.html(works)

def BestellingenDashboard(request):

Data = {'iets': '1'}
return render(request, 'homepage.html', {'bestellingen' : Data})

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

from django.http import HttpResponse
from django.shortcuts import render
from api.models import Bestellingen
import json
import secrets
import requests

URL = ""
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()

def BestellingenDashboard(request):

    Data = {'iets': '1'}
    return render(request, 'homepage.html', {'bestellingen' : Data})

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

0 Answers