Issue - TemplateResponseMixin requires either a definition of 'template_name' or an implementation of 'get_template_names()' [duplicate]

I tried everything to fix this issue, it is so frustrating!!

After the registration (with React) I receive the verification email including the link. After I clicking the link the issue with the "TemplateResponseMixin" appears, no matter what I try...

Here is my code, you can also find the complete on my GitHub repository:

https://github.com/ChrisCross1983/pp5-paw_buddy:

enter image description here

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'),
]

I think also my folder structure is bad, but I'm not sure:

enter image description here enter image description here

It will be so nice if anybody could help me...

Best regards,

Chris

Try to fix this issue with the help of the stack overflow community

Вернуться на верх