Проблема - TemplateResponseMixin требует либо определения 'template_name', либо реализации 'get_template_names()' [duplicate]
Я перепробовал все, чтобы исправить эту проблему, это так расстраивает!!!
После регистрации (с помощью React) я получаю письмо с ссылкой для проверки. После нажатия на ссылку возникает проблема с «TemplateResponseMixin», что бы я ни пытался сделать...
Вот мой код, вы также можете найти полный на моем репозитории GitHub:
https://github.com/ChrisCross1983/pp5-paw_buddy:
введите описание изображения здесь
views.py
from allauth.account.views import ConfirmEmailView
from allauth.account.models import EmailConfirmation, EmailAddress
from django.views.generic.base import TemplateResponseMixin
from django.http import JsonResponse, HttpResponse
from django.template.response import TemplateResponse
from django.views.generic import TemplateView
from django.shortcuts import render
from django.contrib.sites.models import Site
import logging
logger = logging.getLogger(__name__)
class CustomConfirmEmailView(ConfirmEmailView):
template_name = 'account/email_confirmed.html'
def get(self, request, *args, **kwargs):
print("DEBUG: CustomConfirmEmailView gestartet mit Key:", kwargs.get("key"))
try:
confirmation = self.get_object()
print("DEBUG: Confirmation gefunden:", confirmation)
confirmation.confirm(request)
print("DEBUG: Benutzer erfolgreich bestätigt")
user = confirmation.email_address.user
user.is_active = True
user.save()
return JsonResponse({"message": "Email erfolgreich bestätigt"})
except Exception as e:
print(f"DEBUG: Fehler in CustomConfirmEmailView: {e}")
return JsonResponse({"error": str(e)}, status=400)
def test_template_view(request):
return render(request, 'account/email_confirmed.html', {"message": "Test erfolgreich"})
def account_inactive_view(request):
logger.debug("Account Inactive View aufgerufen")
return JsonResponse({"error": "Your account is inactive. Please confirm your email to activate it."}, status=403)
def index(request):
return render(request, 'index.html')
urls.py:
from django.contrib import admin
from django.urls import path, include
from project.views import CustomConfirmEmailView, account_inactive_view, test_template_view
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('project.urls')),
path('dj-rest-auth/', include('dj_rest_auth.urls')),
path('dj-rest-auth/registration/', include('dj_rest_auth.registration.urls')),
path(
'dj-rest-auth/registration/account-confirm-email/<key>/',
CustomConfirmEmailView.as_view(),
name='account_confirm_email',
),
path('account-inactive/', account_inactive_view, name='account_inactive'),
path('test-template/', test_template_view, name='test_template'),
]
Я думаю, что у меня также плохая структура папок, но я не уверен:
введите описание изображения здесь введите описание изображения здесь
Будет очень приятно, если кто-нибудь сможет мне помочь...
С наилучшими пожеланиями,
Крис
Попробуйте исправить эту проблему с помощью сообщества stack overflow