我試圖在我的 utils.py 中匯入模塊六,但它不起作用
from django.contrib.auth.tokens import PasswordResetTokenGenerator
from six import text_type
from django_six import text_type
class AppTokenGenerator(PasswordResetTokenGenerator):
def _make_hash_value(self, user, timestamp):
return (text_type(user.is_active) text_type(user.pk) text_type(timestamp))
account_activation_token = AppTokenGenerator()
但我收到此錯誤“檔案“C:\django\2proj\authentication\utils.py”,第 2 行,從六個匯入 text_type ModuleNotFoundError:沒有名為“六”的模塊”
我正在使用 django 4.0.2
uj5u.com熱心網友回復:
six這些天你不需要;你的代碼相當于
from django.contrib.auth.tokens import PasswordResetTokenGenerator
class AppTokenGenerator(PasswordResetTokenGenerator):
def _make_hash_value(self, user, timestamp):
return f"{user.is_active}{user.pk}{timestamp}"
account_activation_token = AppTokenGenerator()
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/431195.html
標籤:django
上一篇:Queryset多對多“ManyRelatedManager”物件不可迭代
下一篇:員工模型鏈接到Django用戶
