私は招待リンクに問題があるため、既存のDjangoアプリケーションのログインプロセスを更新しようとしています。私が招待状リンクを送った場合、それは予想どおりに機能し、サインアップフォームとサイトにユーザーを引き込みますが、後でその招待リンクを使用して再度サイトにアクセスしようとすると、500エラー(DoesNotExist: User matching query does not exist.
)が返されます。期限切れの招待状リンクをメインログインページにリダイレクトして、500エラーページに行くのではなくログインできるようにします。使用済みのdjango招待リンクのリダイレクト
私はそれは私が使用することができますget_fail_urlを私がホームページにオリジナルのログインを送信するために使用することができますget_success_urlを持っていますが、そこにあることがわかりジャンゴ1.11と招待バックエンド(http://django-organizations.readthedocs.io/en/latest/reference/backends.html)
を使用しています期限切れの招待状リンクをメインのログインページに送信するには?または、この問題にアプローチするより良い方法はありますか?エラーはので、私は、エラーをキャッチしようと-除くステートメントを使用してみなさラインform = self.get_form(data=request.POST or None, instance=user)
で発生すると表示されますが、
class CustomerInvitations(InvitationBackend):
form_class = CustomUserRegistrationForm
def __init__(self):
super().__init__(Customer)
def get_success_url(self):
return "/"
def invite_by_email(self, email, sender=None, request=None, **kwargs):
try:
user = self.user_model.objects.get(email=email)
except self.user_model.DoesNotExist:
user = self.user_model.objects.create(username=self.get_username(), email=email,
password=self.user_model.objects.make_random_password())
user.is_active = False
user.save()
self.send_invitation(user, sender, **kwargs)
return user
def activate_view(self, request, user_id, token):
organization_ids = CustomerUser.objects.filter(user_id=user_id).all().values_list("organization_id", flat=True)
organization_names = Customer.objects.filter(id__in=organization_ids).all().values_list("name", flat=True)
organization_names = list(organization_names)
if len(organization_names) <= 2:
names = " and ".join(organization_names)
else:
organization_names[-1] = "and " + organization_names[-1]
names = ", ".join(organization_names)
user = self.user_model.objects.get(id=user_id, is_active=False)
form = self.get_form(data=request.POST or None, instance=user)
if len(organization_names) and not form.is_valid():
messages.info(request, "Join "+names+" on the website!")
return super().activate_view(request, user_id, token)
:ここ
は私がすべて/招待状/ URLを送るというのが私のCustomerInvitationsクラスです私はこのコードを維持しないので、よりクリーンで理解しやすいソリューションを好むでしょう。
解決策が私が紛失していることが明らかな場合は、私にはご容赦ください。私はちょうど1週間前にDjangoを始めました。これはWebアプリケーションの最初の紹介です。