2013-05-07 82 views
0

您好我不断收到使用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', 
) 
+0

你有没有试过把tastypie放在INSTALLED_APPS的顶部? 此外,useraccount模型的外观如何?你有没有创造它的资源? – nnaelle 2013-05-08 02:38:56

+0

@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

+0

Have you tri在你的tastypie文件中创建Person资源? 你在哪里导入username_field?可能是一个大小写敏感的问题? – nnaelle 2013-05-08 13:57:14

回答

0

为了解决这个我沉浸我的手到tastypie代码和行19它是一个错误被造成的事实后添加

username_field ='username' 

,为用户名对象中没有提及发现如果发生错误的配置错误。

+1

我实际上设法修复它而不修改TastyPie。基本上它归结到我添加post_save信号的地方。它需要在自定义用户代码之后运行的代码中,以便TastyPie可以导入模块并定义字段。 – Prydie 2013-05-17 11:30:56

+0

这似乎是正确的事情我也会尝试改变我的应用程序,谢谢@Prydie – Bwire 2013-05-18 05:02:06

相关问题