I have a front end model developed in reaction with BI dashboards.
I need to send the dataframes treated in pandas as json in the api to be consumed by the frontend
Structure
1st- I use sqlalchemy to connect to the firebird database
2nd- I perform a sql query with pd.readsql() to generate our dataframe and do the other treatments with pandas
What I need
These data treated as dataframes need to be sent as json in an api that will be consumed by a react frontend structure
End part
I thank you for all your help in advance.
I’m a beginner with the framework and I’m stuck in it.
I don’t know what you’re trying to refer to by making a reference to “the Django API”.
A Django view receives a request and returns a response. The contents of that response are determined entirely by the view associated with that request.
In this case, you would want your response to be an instance of a JsonResponse.
Hi, you have to use a to_dict; not a to_json.
The to_json returns a string.
Suposse your dataframe es df, then do this
JSonResponse(df.to_dict())
Because JSonResponse needs a dictionary to serialize to a Json.