Hi all! I'm developing my first public side project. I met some difficulties with Django framework, and now I'm seeking for help.
The task in a nutshell: get two numerical values from the user, manipulate them and give the result in the form of a png plot. I did the whole part related to plotting (pandas+matplotlib), but I can’t figure out how to integrate it to the webapp.
How can I help you in return:
This is my first post here, I wonder what the effect will be. Thanks!
In your view, call the code that generates the image, and return a Response with the binary data
return HttpResponse(binary_image_data, content_type="image/png")You will want to decide if the user data should come from the
GETquery_params or inPOSTdata. But it depend on how you want to use the image. If perhaps you want to embed it in an html<img>tag, you could use query parameters and caching.thx!
You have a few options:
The last option is what I am doing for bar charts in https://yetanothersermon.host and it's working pretty well so far.
Thx for the links!
My problem is that I don't understand how to take 2 values from POST-form and, after that, plot the chart on the next page in Django.
Feel free to fire me an email: dean@yetanothersermon.host
Happy to help
For the best UX you will want to create an AJAX function that takes in them two numerical values.
Then run your script inside that function and then either store the image on the hard drive or send it as the response.
Hope that helped, should give you some things to google.
If you need more help feel free to email, can always hop on a call and help you out.
thx! btw, what is the best solution to host this project (webpage+script)? Heroku will be good for it?
Most likely the easiest options.
I know IH is hosted with https://render.com/
The script will be inside of Django. It won't live by itself anymore. You can make it a package I guess and import it. Otherwise just copy the requirements.txt and the python file into Django project.
This comment was deleted 7 years ago
Hey man, more than happy to help. Experience Django dev
Shoot me an email: hello@dannyaziz.com