您好我不断收到使用Django 1.5自定义用户模型的Tastypie错误。
ImportError at /account/signup/
cannot import name username_field
Request Method: GET
Request URL: http://localhost:8000/account/signup/
Django Version: 1.5.1
Exception Type: ImportError
Exception Value:
cannot import name username_field
Exception Location: /usr/local/lib/python2.7/dist-packages/tastypie /authentication.py in <module>, line 13
我已经看过这个解决here虽然我无法来解决它的错误。当我导入引用tastypie的东西时发生错误,因此我无法修改它。我很感谢你的时间来看待这个。在资源文件中出现错误的代码是:
from models import *
from tastypie.resources import ModelResource
# Resources specific for structures and are location based.
class NotificationResource (ModelResource):
class Meta:
queryset = Notification.objects.all()
allowed_methods = ['get']
而在我安装的应用程序设置中,我有这个。
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'tastypie',
#Local Apps
'useraccounts',
)
你有没有试过把tastypie放在INSTALLED_APPS的顶部? 此外,useraccount模型的外观如何?你有没有创造它的资源? – nnaelle 2013-05-08 02:38:56
@nnaelle感谢您的回复我将tastypie应用放在顶部,但没有变化,我的Person模型如下所示: class Person(AbstractUser): phone_number = models.CharField(max_length = 20,unique = True, db_index = TRUE) 描述= models.TextField(默认为无,空=真) secret_answer = models.CharField(MAX_LENGTH = 255,默认值= “”) #使用的UserManager得到create_user法等 对象= PersonModelManager() USERNAME_FIELD ='phone_number' def get_full_name(self): return self.first_name – Bwire 2013-05-08 07:07:44
Have you tri在你的tastypie文件中创建Person资源? 你在哪里导入username_field?可能是一个大小写敏感的问题? – nnaelle 2013-05-08 13:57:14