I’m working with node js and Django data connection. I have this middleware using node js that can send data using post request.
my node.js
const payload = mydata;
//POST payload to django
var obj = { data: payload };
jsonobj = JSON.stringify(obj);
var XMLHttpRequest = require("xhr2");
var xhr = new XMLHttpRequest();
xhr.open("POST", "http://127.0.0.1:8000/", true);
xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhr.send(jsonobj);
And I can access that data in my django project views.py using this following code. It’s printing the data that node js sent.
from django.views.decorators.csrf import csrf_exempt
import json
@csrf_exempt
def overview(request):
if request.method == 'POST':
post_data = json.loads(request.body.decode("utf-8"))
value = post_data.get('data')
print(value)
return render(request, 'myhtml')
how can I pass this data (value = post_data.get(‘data’)) into a Plotly dash callback function. I tried this function, but I think it will not recognize request
@app.callback(Output('graph-ph', 'figure'),
[Input('interval-graph-update', 'n_intervals')],
[State('graph-ph', 'figure')])
def update_extend_traces_traceselect(n_intervals, fig_raw, request):
if request.method == 'POST':
post_data = json.loads(request.body.decode("utf-8"))
value = post_data.get('data')
print(value)