【问题标题】:basic http authentication with django-piston使用 django-piston 进行基本的 http 身份验证
【发布时间】:2010-07-21 07:36:03
【问题描述】:

我是新手。我在官方网站上看到了代码 sn-p(粘贴在下面)。 问题是如何将其部署到服务器?我在哪里设置用户名和密码凭据?在 Apache 的 httpd.conf 文件中?


from django.conf.urls.defaults import *
from piston.resource import Resource
from piston.authentication import HttpBasicAuthentication

from myapp.handlers import BlogPostHandler, ArbitraryDataHandler

auth = HttpBasicAuthentication(realm="My Realm")
ad = { 'authentication': auth }

blogpost_resource = Resource(handler=BlogPostHandler, **ad)
arbitrary_resource = Resource(handler=ArbitraryDataHandler, **ad)

urlpatterns += patterns('',
    url(r'^posts/(?P<post_slug>[^/]+)/$', blogpost_resource), 
    url(r'^other/(?P<username>[^/]+)/(?P<data>.+)/$', arbitrary_resource), 
)

【问题讨论】:

  • 什么是“这个”? django?活塞?

标签: python django django-piston


【解决方案1】:

默认情况下piston.authenticate.HttpBasicAuthentication 使用 django.contrib.auth.authenticate 检查凭据。

换句话说:您只需通过创建普通 Django 用户来“设置用户名和密码凭据”。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-08-12
    • 2013-05-24
    • 2015-09-07
    • 2017-05-25
    • 1970-01-01
    • 2017-06-13
    • 2013-05-30
    相关资源
    最近更新 更多