global name 'get_user_model' is not defined

£可爱£侵袭症+ 提交于 2020-07-09 06:39:09

问题


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

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

line 770:

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

Why does get_user_model() not work? Any suggestions?


回答1:


You need to add the import to your views.py.

from django.contrib.auth import get_user_model


来源:https://stackoverflow.com/questions/37471735/global-name-get-user-model-is-not-defined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!