Python中文
首页
教程
问答
标签
搜索
登录
注册
如何在Django视图中返回HTML?
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我试图在浏览器上显示matlib绘图,我使用的是Django。到目前为止,我已经:</p> <pre><code>import matplotlib.pyplot as plt import base64 from io import BytesIO fig = plt.figure() #plot sth tmpfile = BytesIO() fig.savefig(tmpfile, format='png') encoded = base64.b64encode(tmpfile.getvalue()) html = 'Some html head' + '<img src=\'data:image/png;base64,{}\'>'.format(encoded) + 'Some more html' with open('test.html','w') as f: f.write(html) </code></pre> <p>但是,我想要的不是f.write(html),而是:</p> <pre><code>return render_to_response(html) </code></pre> <p>如何处理一个大的html字符串?你知道吗</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>你试过<a href="https://docs.djangoproject.com/en/2.1/ref/request-response/#httpresponse-objects" rel="nofollow noreferrer">HttpResponse</a>吗?你知道吗</p> <pre><code>return HttpResponse("<p>Some html</p>") </code></pre>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
为什么我的神经网络模型的准确性不能在这个训练集上得到提高?
2 回答
为什么我的神经网络模型的权重变化不大?
5 回答
为什么我的神经网络的成本不断增加?
6 回答
为什么我的神经网络的输入pickle文件是19GB?
1 回答
为什么我的神经网络给属性错误?“非类型”对象没有属性“形状”
7 回答
为什么我的神经网络训练这么慢?
10 回答
为什么我的神经网络输出错误?
2 回答
为什么我的神经网络预测适用于MNIST手绘图像时是正确的,而适用于我自己的手绘图像时是不正确的?
6 回答
为什么我的神经网络验证精度比我的训练精度高,而且它们都是常数?
1 回答
为什么我的私人用户间聊天会显示在其他用户的聊天档案中?
2 回答
为什么我的积分的绝对误差估计值大于积分(使用scipy.integrate.nqad)?
9 回答
为什么我的积层回归器得分比它的组件差?
2 回答
为什么我的移动方法不起作用?
10 回答
为什么我的稀疏张量不能转换成张量
3 回答
为什么我的稀疏张量不能转换成张量?
1 回答
为什么我的程序“停止”了?
6 回答
为什么我的程序一直试图占用所有可用的CPU
1 回答
为什么我的程序不使用指定的代理
8 回答
为什么我的程序不工作(python帮助中的反向函数)?
10 回答
为什么我的程序不工作时,我使用多处理模块
8 回答