I have a method in views.py that creates an image and also creates a text string to return to a template for display. The string is dependent on the dynamically generated image, so I need the image to be created, then create the string, then return both to a view. I am not using a backend currently due to not desiring to keep photos, and strings around taking up space (user does not need it).
Trying different things below:
This code shows just the image correctly(without the string showing up since not returned):
response = HttpResponse(content_type='image/png')
image.save(response, "PNG")
return response
This code just displays text:
##return text
response=HttpResponse()
response.write(the_string)
return response
This code doesn't quite work right as it just displays text (the PIL photo object text string instead of the image, the string is displayed correctly)
objects_to_render = {"photo":image,"string":the_string}
return render(request, "pic_text_display.html",objects_to_render, content_type='image/png')
In "pic_text_display.html":
{{photo}}
{{string}}
Here is the output from above:
<PIL.Image.Image image mode=RGBA size=512x512 at 0x7FCEA377FED0>
the string
How can I return an image and have the string available for display in the template at the same time? I am sure there is a better way to do this than I have been...
Note that I am not using a backend model as I am not storing the attribute, just want to create the string and image, and return both for display. I seem to be having issues as I have different content types, or don't know the right syntax.
Thanks for the help!!