我将我的Django式照相机安装到一个遥远的服务器上,但信使式照相机在遥远的服务器上打上了标记。
我拥有一种信使资源,可以过滤目前安装在用户中的所有物体:
def apply_authorization_limits(self, request, object_list):
return object_list.filter(user=request.user)
当我试图就物体的终点提出GET的请求时,我发现以下错误:
int() argument must be a string or a number, not AnonymousUser
我猜测,因为原木不正确工作?
还是这样? 在模板网页上,我有以下代码:
{% if user.is_authenticated %}
Logged in as <strong>{{ user.username }}</strong>
<a href="/users/logout">Logout</a>
{% else %}
<a href="/users/signup">Signup</a>
<a href="/users/login">Login</a>
{% endif %}
守则正确地显示用户名称(这意味着用户已经认证)。 怎么办? 在我的当地服务器上,我能够成功地向塔斯蒂皮涅狄格世界大会提出所有要求,我不称为AnonymousUser,而是在我的边远服务器上,我称作Tastypie的AnonymousUser。
Edit: When I have a print statement printing out request.user in any view, I get the correct logged in user. When I have a print statement in my Tastypie api.py that prints out request.user, then I am known as AnonymousUser. Why would I be known as AnonymousUser to Tastypie but not to the rest of the application?
Edit: I am using the following authentication:
authentication = Authentication()
If I changed the authentication to ApiKeyAuthentication, then I would have to post the username and api key on each GET/POST request to a Resource. The problem with doing that is that I would have to create a new intermediate view which queried for the username and the view and then did the GET/POST to the Tastypie endpoint. Is there another solution for this? The second way is to embed the username and apikey into the webapp and get JS to grab those values and add them to the GET/POST querystring, but this could lead to a security issue. It would be a security issue because a user could pretend to be another user if they had their username and api key.