带有SessionAuthentication错误的Tastypie:return getattr(request.user,username_field)

时间:2014-07-14 18:54:57

标签: django tastypie

我在Tastypie中使用SessionAuthentication并收到以下错误。当我在本地运行应用程序时,只有在使用uWSGI部署应用程序时,才会显示此错误。

  

{" error_message":" getattr():属性名称必须是字符串",   "追溯":"追溯(最近一次呼叫最后一次):\ n \ n文件   \" /venv/lib/python2.7/site-packages/tastypie/resources.py \",第201行,   in wrapper \ n response = callback(request,* args,** kwargs)\ n \ n   File \" /venv/lib/python2.7/site-packages/tastypie/resources.py \",line   432,在dispatch_list \ n中返回self.dispatch(' list',request,   ** kwargs)\ n \ n文件\" /venv/lib/python2.7/site-packages/tastypie/resources.py\" ;,第460行,   in dispatch \ n self.throttle_check(request)\ n \ n文件   \" /venv/lib/python2.7/site-packages/tastypie/resources.py \",第557行,   在throttle_check \ n identifier =   self._meta.authentication.get_identifier(request)\ n \ n文件   \" /venv/lib/python2.7/site-packages/tastypie/authentication.py \",line   283,在get_identifier \ n中返回getattr(request.user,   username_field)\ n \ nTypeError:getattr():属性名必须是   串\ n"}

uWSGI ini看起来像这样:

[uwsgi]
socket = x.x.x.x:x
chdir = /project/
pythonpath = /venv/lib/python2.7/site-packages
env= DJANGO_SETTINGS_MODULE=project.production_settings
module = project.wsgi
processes = 8
threads = 2
buffer-size=32768
master = True
protocol = uwsgi
logto = /project/uwsgi_error.log

当我向API添加一些相关资源时,似乎也出现了这个问题。特别是,我将另一个应用程序中的模型作为外键导入。从概念上讲,它是这样的:

class Employee(BaseModel):
    employee = models.ForeignKeyField('store.Store')

然后在api.py

import models
from store import models as store_models

class StoreResource(ModelResource):
    class Meta:
        queryset = store_models.Store.objects.all()
        authentication = SessionAuthentication()

class EmployeeResource(ModelResource):
    store = fields.ForeignKey(StoreResource, 'store', full=True)
    class Meta:
       queryset = models.Employee.objects.all()
       authentication = SessionAuthentication()

0 个答案:

没有答案