我正在使用SessionAuthentication与Tastypie并收到以下错误 . 仅当我使用uWSGI部署应用程序时,本地运行应用程序时才会显示此错误 .

{“error_message”:“getattr():属性名称必须是字符串”,“traceback”:“Traceback(最近一次调用最后一次):\ n \ n File \”/ venv / lib / python2.7 / site-packages /tastypie/resources.py \“,第201行,在包装器中\ n response = callback(request,* args,** kwargs)\ n \ n File \”/ venv / lib / python2.7 / site-packages / tastypie /resources.py \“,第432行,在dispatch_list \ n中返回self.dispatch('list',request,** kwargs)\ n \ n File \”/venv/lib/python2.7/site-packages/tastypie /resources.py \“,第460行,在dispatch \ n self.throttle_check(请求)\ n \ n文件\”/ venv / lib / python2.7 / site-packages / tastypie / resources.py \“,第557行,在throttle_check \ n identifier = self._meta.authentication.get_identifier(request)\ n \ n File \“/ venv / lib / python2.7 / site-packages / tastypie / authentication.py \”,第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()