簡體   English   中英

如何在Django中將文本鍵轉換為十六進制,反之亦然?

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

我正在嘗試以十六進制格式將長文本保存在Django數據庫中。 這是一些秘密鑰匙。 同樣在某些時候,我想再次將它們轉換為文本。

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


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

編碼:

text = "hello"

text.encode("hex")

解碼:

hexcode = <hex value>

hexcode.decode("hex")

我希望這有幫助。 :)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM