我正在使用Django 2.0+,并试图将现有的密码重置功能插入我的网站。如果电子邮件不存在,它将成功提交。如果它确实存在,则会出现以下错误:
'microsecond' is an invalid keyword argument for replace()
我从未接触过这个函数的任何后端代码,所以我认为它只是开箱即用
回溯:
C:\Users\djank\documents\github\lfgm_2019\lib\site-packages\django\core\handlers\exception.py in inner
response = get_response(request) …
▶ Local vars
C:\Users\djank\documents\github\lfgm_2019\lib\site-packages\django\core\handlers\base.py in _get_response
response = self.process_exception_by_middleware(e, request) …
▶ Local vars
C:\Users\djank\documents\github\lfgm_2019\lib\site-packages\django\core\handlers\base.py in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs) …
▶ Local vars
C:\Users\djank\documents\github\lfgm_2019\lib\site-packages\django\views\generic\base.py in view
return self.dispatch(request, *args, **kwargs) …
▶ Local vars
C:\Users\djank\documents\github\lfgm_2019\lib\site-packages\django\utils\decorators.py in _wrapper
return bound_method(*args, **kwargs) …
▶ Local vars
C:\Users\djank\documents\github\lfgm_2019\lib\site-packages\django\utils\decorators.py in _wrapped_view
response = view_func(request, *args, **kwargs) …
▶ Local vars
C:\Users\djank\documents\github\lfgm_2019\lib\site-packages\django\contrib\auth\views.py in dispatch
return super().dispatch(*args, **kwargs) …
▶ Local vars
C:\Users\djank\documents\github\lfgm_2019\lib\site-packages\django\views\generic\base.py in dispatch
return handler(request, *args, **kwargs) …
▶ Local vars
C:\Users\djank\documents\github\lfgm_2019\lib\site-packages\django\views\generic\edit.py in post
return self.form_valid(form) …
▶ Local vars
C:\Users\djank\documents\github\lfgm_2019\lib\site-packages\django\contrib\auth\views.py in form_valid
form.save(**opts) …
▶ Local vars
C:\Users\djank\documents\github\lfgm_2019\lib\site-packages\django\contrib\auth\forms.py in save
'token': token_generator.make_token(user), …
▶ Local vars
C:\Users\djank\documents\github\lfgm_2019\lib\site-packages\django\contrib\auth\tokens.py in make_token
return self._make_token_with_timestamp(user, self._num_days(self._today())) …
▶ Local vars
C:\Users\djank\documents\github\lfgm_2019\lib\site-packages\django\contrib\auth\tokens.py in _make_token_with_timestamp
self._make_hash_value(user, timestamp), …
▶ Local vars
C:\Users\djank\documents\github\lfgm_2019\lib\site-packages\django\contrib\auth\tokens.py in _make_hash_value
login_timestamp = '' if user.last_login is None else user.last_login.replace(microsecond=0, tzinfo=None)
我确实有一个使用的CustomUser模型,但我看不出是否存在连接,或者,如果有,连接可能在哪里
救命啊
您可以导航到tokens.py并修改:
发件人:
user.last_login.replace(microsecond=0,tzinfo=None)
致:
user.last_login.replace()
这不是一个理想的解决方案,可能会引入其他无法预见的错误
更好的解决方案
更好的解决方案是在您的CustomUser模型上,将任何加入日期或上次登录(基本上是与日期相关的参数)更改为使用
DateTimeField
而不是DateField
DateTimeField
包括tokens.py所期望的日期和时间简短的例子
请记住,因为您使用的是CustomUser模型,所以需要添加一个AccountManger类来处理
create_user()
和create_superuser()
只需转到
tokens.py
文件(对我来说,它位于这里:AppData\Local\Programs\Python\Python38-32\Lib\site-packages\django\contrib\auth\tokens.py
)并更改以下行:到
相关问题 更多 >
编程相关推荐