Django 活塞、Django.auth 和 asihttprequest

发布于 2024-11-26 23:44:17 字数 543 浏览 2 评论 0原文

我有一个使用 Django 活塞作为 API 的网站。我还创建了一个 iPhone 应用程序,它成功连接到 API 并解析 JSON 并在 iPhone 上显示正确的内容。 API 资源 URL 如下

http:/mysite.com/api/pics

http:/mysite.com/api/pics/username

我目前正在 iPhone 应用程序中将用户名硬编码到上述 URL 中,并且没有根本没有认证。我希望这些 URL 要求用户进行身份验证。

我的网站允许通过 Django 提供的 /accounts/login 登录。然而,代码将用户重定向到他们在网站上的个人资料,因此我假设我不能仅在 iPhone 的 asihttprequest 中使用此 URL。

因此,如果我想使用 Django 内置的身份验证系统登录用户,我应该将他们指向什么 URL。另外,一旦用户通过身份验证,我知道我应该对活塞中的任何“受保护资源”使用“已通过身份验证”和“挑战”。我看过定义这些函数的代码片段,但我不确定在哪里以及如何实现它们。我习惯使用只写@login_required 的装饰器。

I have a website that uses Django piston for the API. I have also created an iPhone app that successfully connects to the API and parses the JSON and displays the correct content on the iPhone. The API resource URLs are as follows

http:/mysite.com/api/pics

http:/mysite.com/api/pics/username

I'm currently hard coding the username into the above URL from within the iPhone app and there is no authentication at all. I would like these URLs to require the user to be authenticated.

My website allows logging in via the /accounts/login provided by Django. However, the code redirects the users to their profile on the website, so I'm assuming I can't just use this URL in an asihttprequest from the iPhone.

So, if I want to log a user in, using the Django's built in authentication system, what URL should I be pointing them to. Also, once the user is authenticated I know that I'm supposed to use "is authenticated" and "challenge" for any "protected resource" in piston. I've seen code snippets that define these functions but I'm not sure where and how to implement them. I'm used to using a decorator that just says @login_required.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

山人契 2024-12-03 23:44:17

如果您按照以下说明进行操作: http://yml- blog.blogspot.com/2009/10/django-piston-authentication-against.html 然后查看示例应用程序 urls.py 文件 https://bitbucket.org/yml/django-piston /src/dfb826a31ca8/examples/blogserver/api/urls.py 您将看到身份验证已传递到资源处理程序。

如果您已经这样做了,则无需使用装饰器:)

if you followed the instructions at: http://yml-blog.blogspot.com/2009/10/django-piston-authentication-against.html then looking at the example applications urls.py file https://bitbucket.org/yml/django-piston/src/dfb826a31ca8/examples/blogserver/api/urls.py you will see that authentication is passed to the resource handler.

If you've done this there is no need to use a decorator :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文