全球名称' get_user_model'没有定义

时间:2016-05-26 22:00:30

标签: python django django-models django-views nameerror

/ project / reset_password_confirm / MTQ-4c8-65d880f1c28996091226 /

NameError

global name 'get_user_model' is not defined
Request Method: POST
Django Version: 1.9.1
Exception Type: NameError
Exception Value:    
global name 'get_user_model' is not defined
Exception Location: /root/django/studie/project/views.py in post, line 770
Python Executable:  /usr/bin/python
Python Version: 2.7.9

views.py

from django.contrib.auth.models import User

第770行:

    def post(self, request, uidb64=None, token=None, *arg, **kwargs):
    UserModel =  get_user_model()
    ....

为什么get_user_model()不起作用?有什么建议吗?

1 个答案:

答案 0 :(得分:1)

您需要将导入添加到views.py

from django.contrib.auth import get_user_model