views.py 我使用django-allauth。在迁移之前,此代码有效。在迁移之后,他引用了组并给出了错误
def teachers(request):
group = models.Group.objects.get(name='teachers')
list_teachers = group.user_set.all()
return render(
request,
'teachers.html',
{
'list_teachers' : list_teachers
}
)
Internal Server Error: /teachers/
Traceback (most recent call last):
File "C:\python 3.7.4\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\python 3.7.4\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\python 3.7.4\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\Homie\Desktop\defenseMilestone\defense\milestone\views.py", line 55, in teachers
group = models.Group.objects.get(name='teachers')
AttributeError: module 'allauth.models' has no attribute 'Group'
[13/Dec/2019 16:50:51] "GET /teachers/ HTTP/1.1" 500 66823
答案 0 :(得分:1)
您正在尝试从allauth.models
导入allauth
,但是Group
没有定义django.contrib.auth.models
。如下所示从from django.contrib.auth.models import Group
def teachers(request):
group = Group.objects.get(name='teachers')
list_teachers = group.user_set.all()
return render(
request,
'teachers.html',
{
'list_teachers' : list_teachers
}
)
导入它:
const textField =...
请尝试这个。