1

パスワードをリセットするときに、サッチモ ストアが HTML 形式のメールを送信するようクライアントから要求されました。

どうやら satchmo または django の contrib.auth.views.password_reset は未加工の電子メールのみを送信します。

HTML 形式のメールを送信できるようにするには、これをどのように変更すればよいですか?

ありがとうございました!

4

1 に答える 1

5

私は Satchmo を使ったことがありませんが、これで始められるはずです。

まず、 をサブクラス化し、プレーン テキスト メールの代わりに HTML メールを送信するようにメソッドをPasswordResetFormオーバーライドします。save

from django.contrib.auth.forms import PasswordResetForm

class HTMLPasswordResetForm(PasswordResetForm):
    def save(self, domain_override=None, email_template_name='registration/password_reset_email.html',
             use_https=False, token_generator=default_token_generator, from_email=None, request=None):
        """
        Generates a one-use only link for resetting password and sends to the user
        """
        # Left as an exercise to the reader

既存のPasswordResetFormものをガイドとして使用できます。send_mailHTMLメールを送信するには、最後の呼び出しをコードに置き換える必要があります。HTMLメールの送信に関するドキュメントが役立ちます。

フォームを作成したら、そのフォームを の URL パターンに含める必要がありますpassword_reset。おっしゃる通り、私はサッチモの経験はありませんが、ソースコードを見るとsatchmo_store.accounts.urls、password_reset_dict を変更して更新したいと思います。

# You need to import your form, or define it in this module
from myapp.forms import HTMLPasswordResetForm

#Dictionary for authentication views
password_reset_dict = {
    'template_name': 'registration/password_reset_form.html',
    # You might want the change the email template to .html
    'email_template_name': 'registration/password_reset.txt',
    'password_reset_form': HTMLPasswordResetForm,
}

# the "from email" in password reset is problematic... it is hard coded as None
urlpatterns += patterns('django.contrib.auth.views',
    (r'^password_reset/$', 'password_reset', password_reset_dict, 'auth_password_reset'),
    ...
于 2011-04-06T23:28:03.927 に答える