A
A
AntVlad2022-04-15 14:30:57
Django
AntVlad, 2022-04-15 14:30:57

How to fix 'function' object has no attribute 'as_view' error?

I'm making an authorization system on Django 4.0.3.

views.py
from django.http import HttpResponse, Http404
from django.template import TemplateDoesNotExist
from django.template.loader import get_template
from django.shortcuts import render

from django.contrib.auth.views import LoginView, LogoutView
from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.auth.decorators import login_required

def MyLoginView(LoginView):
  template_name = 'main/login.html'

def MyLogoutView(LoginRequiredMixin,LogoutView):
  template_name = 'main/logout.html'
...


urls.py
from django.urls import path
from .views import index, other_page, MyLoginView, MyLogoutView, profile

app_name='main'
urlpatterns = [
  path('accounts/login/', MyLoginView.as_view(), name='login'),
  path('accounts/logout/', MyLogoutView.as_view(), name='logout'),
        ....
]


I get an error

File "./bboard/main/urls.py", line 7, in
path('accounts/login/', MyLoginView.as_view(), name='login'),
AttributeError: 'function' object has no attribute 'as_view '


How to fix? I do everything according to the tutorial, so the author works. I don't see any grammatical errors, maybe it's the Django version?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2022-04-15
@AntVlad

why suddenly you have MyLoginView and MyLogoutView functions and not classes?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question