ユーザー名ではなくメールでユーザーを認証しようとしています。
私はdjango-userena
そのドキュメントなどを使用しています。必要なものはほとんど何でも設定します。のようなもの:USERENA_WITHOUT_USERNAMES = True
その設定などで。
しかし、サインアップした後、私は一連の問題に直面しました。認証、サインアップ完了の問題などのために、URLでユーザー名を渡そうとするようなものです。
引数としてユーザー名を必要とするいくつかのビュー関数を変更しましたが、このメソッドは私の問題を解決せず、それを行うための正しい(そしておそらく安全な)方法でもありません。
たとえば、このURLにルーティングするとhttp://127.0.0.1:8000/accounts/signup/complete/
(後$ ./manage.py check_permissions
)、次のエラーが発生します。
global name 'username' is not defined
/userena/views.py in directto_user_template
user = get_object_or_404(User, username_iexact=username)
足りないものはありますか?
更新: これが私が得る出力です:
レンダリング中にNoReverseMatchがキャッチされました:引数'(' xyz@xyz.com'、' 70b60d1d97015e03ba8d57f31e4c7ff14d6ab753')'およびキーワード引数'{}'が見つからない'userena_activate'のリバース。
userenaが次のURLのユーザー名としてメールを送信しようとしていることは明らかです。
userena / templates / userena / emails / Activation_email_message.txt、8行目のエラー
1 {% load i18n %}{% autoescape off %}
2 {% if not without_usernames %}{% blocktrans with user.username as username %}Dear {{ username }},{% endblocktrans %}
3 {% endif %}
4 {% blocktrans with site.name as site %}Thank you for signing up at {{ site }}.{% endblocktrans %}
5
6 {% trans "To activate your account you should click on the link below:" %}
7
8 {{ protocol }}://{{ site.domain }}{% url userena_activate user.username activation_key %}
9
10 {% trans "Thanks for using our site!" %}
11
12 {% trans "Sincerely" %},
13 {{ site.name }}
14 {% endautoescape %}
更新2:
わかりました。クラスフォームのソースコードを読み取るSignupFormOnlyEmail
と、ランダムなユーザー名が自動的に生成されることがわかります。
class SignupFormOnlyEmail(SignupForm):
"""
Form for creating a new user account but not needing a username.
This form is an adaptation of :class:`SignupForm`. It's used when
``USERENA_WITHOUT_USERNAME`` setting is set to ``True``. And thus the user
is not asked to supply an username, but one is generated for them. The user
can than keep sign in by using their email.
"""
def __init__(self, *args, **kwargs):
super(SignupFormOnlyEmail, self).__init__(*args, **kwargs)
del self.fields['username']
def save(self):
""" Generate a random username before falling back to parent signup form """
while True:
username = sha_constructor(str(random.random())).hexdigest()[:5]
try:
User.objects.get(username__iexact=username)
except User.DoesNotExist: break
self.cleaned_data['username'] = username
return super(SignupFormOnlyEmail, self).save()
アップデート :
私はついに問題を解決しました。django-email-as-username
横にも使っていましたdjango-userena
。これが私の問題の原因でした。どうやら、彼らはいくつかの対立を持っています。気を付けて