【问题标题】:Django Customized Forgot Password error (custom user model)Django Customized Forgot Password 错误(自定义用户模型)
【发布时间】:2021-10-21 07:12:52
【问题描述】:

寻求帮助!即使我正在改进,我也没有编写 Python/后端代码的经验。在开发/本地服务器中,我正在尝试创建自定义密码重置表单...但是在测试表单时提交电子邮件后出现以下错误,并且从未收到带有链接的电子邮件:

save() 得到了一个意外的关键字参数 'use_https'

我的自定义忘记密码表单

class PrivateForgotPasswordForm(forms.ModelForm):
    helper = FormHelper()
    helper.add_input(Submit('page_userForgotPassword_content_form_button_submit',
                            static_textLanguage['global_button_submit'],
                            css_class='global_component_button'))

    class Meta:
        model = PrivateUser
        fields = ['email']
        widgets = { 'email': forms.EmailInput(attrs={
                    'id': 'page_userForgotPassword_content_form_input_email',
                    'maxlength': '254',
                    'class': 'global_component_input_box'}
                    )
        }

    def __init__(self, *args, **kwargs):
        super(PrivateForgotPasswordForm, self).__init__(*args, **kwargs)
        self.helper.form_id = 'page_userForgotPassword_content_form'
        self.helper.form_method = 'post'
        self.helper.form_action = ''
        self.helper.form_class = 'page_userForgotPassword_content_form'

我的自定义忘记密码视图

class UserForgotPasswordView(auth_views.PasswordResetView):
    with open(str(settings.BASE_DIR) + "/frontend/static/frontend/languages/emails/EN/email_footer__main.json", "r") as temp_file_email_footer_main:
        email_footer_main_data = json.load(temp_file_email_footer_main)
    with open(str(settings.BASE_DIR) + "/frontend/static/frontend/languages/emails/EN/email_user_forgotPassword.json", "r") as temp_file_email_forgot_password:
        email_forgot_password_data = json.load(temp_file_email_forgot_password)
    extra_email_context = { 'email_footer_static_json_text': email_footer_main_data,
                            'email_static_json_text': email_forgot_password_data,
                            'static_json_text': static_textLanguage, 
                            'static_json_textGlobal': static_textGlobal}
    html_email_template_name = '../frontend/templates/frontend/templates.emails/template.email_user_forgotPassword.html'
    from_email = 'support@xyz.com'
    subject_template_name = 'Reset password'
    template_name = '../frontend/templates/frontend/templates.user/template.page_forgotPassword.html'
    form_class = PrivateForgotPasswordForm
    success_url = reverse_lazy('password_reset_done')
    
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        context = { 'forgot_password_form': PrivateForgotPasswordForm(),
                    'email_subject': self.email_forgot_password_data['emailSubject'],
                    'static_json_text': static_textLanguage, 
                    'static_json_textGlobal': static_textGlobal}
        return context

【问题讨论】:

    标签: django passwords


    【解决方案1】:

    您想要创建自定义密码重置表单的原因是什么? Django 有一个非常充足的内置功能来处理这个问题。

    【讨论】:

    • 好问题。也许更改表单没有意义,但就视图(在模板上)而言,我希望能够灵活地动态更改文本(在这种情况下为 json 文件)。这有意义吗?如果我删除自定义表单,错误可能消失了吗?
    猜你喜欢
    • 2021-10-27
    • 1970-01-01
    • 1970-01-01
    • 2017-07-13
    • 2013-04-29
    • 2021-08-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多