Hi All,
I am new to Django and Dash and having trouble passing received POST request data to a DjangoDash app instance (in django-plotly-dash). The data being sent in the POST request is originating from another host, but I have CORS headers worked out, and the data is actually turning up in the views method (outlined below).
In “settings.py”, the PLOTLY_DASH value for ‘cache_arguments’ is set to True.
In “views.py”, I have a function which receives requests and returns a rendered template response. If the request method is POST, it gets the json data that was posted, dumps it to a string, and then puts that data string into the context dict…
@csrf_exempt
def session_state_view(request, template_name, **kwargs):
context = {}
for k,v in request.session.items():
context[k]=v
if request.method == 'POST':
data_str = json.dumps(json.loads(request.body)["data"], ensure_ascii=False)
context['posted_data'] = data_str
context['django_plotly_dash']['posted_data'] = data_str
return TemplateResponse(request, template_name, context)
In the app, there is an expanded_callback where I try to get ‘posted_data’ out of the kwargs ‘session_state’ with ‘django_plotly_dash’…
@app.expanded_callback(
Output('posted_data', 'children'),
[Input('some_number', 'children')]
)
def update_posted_data(some_number, **kwargs):
sess_state = kwargs.get('session_state',dict())
dpd_state = sess_state.get('django_plotly_dash', dict())
posted_json_str = dpd_state.get('posted_data', None)
return posted_json_str
Then ‘posted_data’ is returned as the child of an html.Div… except that it isn’t working. ‘posted_json_str’ is always None. What am I missing?
Apologies if this question has been answered numerous times before.
Many thanks in advance,
Sam