English 中文(简体)
Tastypie承认用户为匿名 用户
原标题:Tastypie recognizes logged in user as AnonymousUser

我将我的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.

最佳回答

First: APIKeyAuth: It s as much of an issue as if another user gets the username and password, or the session id over an insecure connection.

第二: 如果你想要使用基于会议认证的认证(只有浏览器的作品,目前则在用户中贴上标签) 你们需要创建自己的认证支持,详见以下网址:

Scroll up a bit from there though, and read the nasty warning about the Authentication method that you have chosen.

问题回答

暂无回答




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签