简体   繁体   English

如何在Django中将文本键转换为十六进制,反之亦然?

[英]How to convert a text keys into hex in Django and viceversa?

I am trying to save a long text in hex format in Django database. 我正在尝试以十六进制格式将长文本保存在Django数据库中。 This are some secret keys. 这是一些秘密钥匙。 Also at some point I want to convert them to text again. 同样在某些时候,我想再次将它们转换为文本。

def import_keys(request):
    if request.method == "POST":
        secrets = request.POST['text_file']


        some = secrets.encode("hex")       
        Keys.objects.create(hexa=some)

to encode:: 编码:

text = "hello"

text.encode("hex")

to decode:: 解码:

hexcode = <hex value>

hexcode.decode("hex")

I hope this helps. 我希望这有帮助。 :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM