Python:如何在浏览器中显示计算出的MD5值?
我得到了这个Python代码,它可以计算任何短语的MD5值:(
import md5
md5.new("Nobody inspects the spammish repetition").digest()
这里的短语是:“没有人检查垃圾邮件重复”)
我想做的是在浏览器中显示这个值。我如何在 Python 中做到这一点?
我尝试了所有这些变体,但都不起作用:
import md5
show = md5.new("Nobody inspects the spammish repetition").digest()
print show
import md5
print md5.new("Nobody inspects the spammish repetition").digest()
import md5
md5.new("Nobody inspects the spammish repetition").digest()
print md5
import md5
md5.new("Nobody inspects the spammish repetition").digest()
print md5.new
更新 A:
到目前为止(2010 年 4 月 5 日星期一,07:19:35 GMT)我收到了来自 Ignacio Vazquez-Abrams 和 Ji 的两个答案。两者都提出了几乎相同的建议。我已经尝试过Ji的代码,但没有成功。这是我收到的错误行的屏幕截图:
(来源:narod.ru)
(我相信你需要右键单击图像并选择“查看图像”才能以更大的尺寸查看它)
I was given this Python code that would calculate an MD5 value for any phrase:
import md5
md5.new("Nobody inspects the spammish repetition").digest()
(The phrase here is: "Nobody inspects the spammish repetition")
What I want to do is display this value in my browser. How do I do it in Python?
I tried all these variants, none of them worked:
import md5
show = md5.new("Nobody inspects the spammish repetition").digest()
print show
import md5
print md5.new("Nobody inspects the spammish repetition").digest()
import md5
md5.new("Nobody inspects the spammish repetition").digest()
print md5
import md5
md5.new("Nobody inspects the spammish repetition").digest()
print md5.new
update A:
By now (Monday, 5 April 2010, 07:19:35 GMT) I have received two answers from Ignacio Vazquez-Abrams and from Ji. Both have suggested pretty much the same thing. I have tried Ji's code, but it didn't work. Here is the screen shot of the error lines I received:
(source: narod.ru)
(I believe you need to right click on the image and choose "View the Image" to see it in a bigger size)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了在浏览器中显示十六进制摘要,您需要某种 Web 框架(在本例中为 Python)来为您处理所有 Web 服务。
这是一个使用 web.py 的示例(我复制了默认示例并针对 md5 进行了调整)。但你可以使用任何其他框架
In order to display the hexdigest in your browser you need to have some sort of web framework (in this case in python) that handles all the web serving for you.
Here's an example using web.py (I've copied the default example and adjusted for the md5). But you can use any other framework out there
.hexdigest()
就是你想要的。.hexdigest()
is what you want.