我为Login和Logout创建了一个基于类的视图,当使用.as_view()调用时,该视图完全可以正常工作,但是如果我将其用于其他应用程序,则该函数对象将没有as_view属性
创建了一个基于类的视图 将其添加到url.py 创建了新的app-> model-> form->基于类的视图
secondApp / views.py
from django.http import HttpResponse
from django.shortcuts import render, redirect
from django.core.mail import send_mail, EmailMessage, BadHeaderError
from django.template.loader import render_to_string
from django.contrib.sessions.models import Session
from django.views.generic import CreateView, View
from django.conf import settings
from .forms import *
from .models import *
from login.models import User
class addDirector(CreateView):
form_class = addDirectorMultiForm
template_name = 'admin/add_director_account.html'
success_url = 'administrator/'
def form_valid(self, form):
user = form['user'].save()
profile = form['profile'].save()
return redirect(self.success_url)
urls.py
from administrator import views
urlpatterns = [
path('admin/', admin.site.urls),
#accounts
path('accounts/', include('django.contrib.auth.urls')),
path('', HomeView.as_view(), name='home'),
path('accounts/login', LoginView.as_view(), name = 'LoginView'),
# Admin
path('administrator/', views.admin_home_view, name = 'admin_home_view'),
path('administrator/add_director', views.addDirector.as_view(), name = 'addDirector'),
]
error_message:
path('administrator / add_director',views.addDirector.as_view(),name ='addDirector'),
AttributeError:“函数”对象没有属性“ as_view”