使用django-piston进行基本的HTTP身份验证 [英] basic http authentication with django-piston

查看:76
本文介绍了使用django-piston进行基本的HTTP身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm a newb to this. I've seen the code snippet at the official site (pasted below). The problem is how do I deploy this to the server ? Where do I set the username and password credentials ? In the httpd.conf file for Apache ?

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), 
)

推荐答案

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

By default piston.authenticate.HttpBasicAuthentication uses django.contrib.auth.authenticate to check credentials.

换句话说:您只需创建普通的Django用户即可设置用户名和密码凭据".

In other words: you "set username and password credentials" simply by creating normal Django Users.

这篇关于使用django-piston进行基本的HTTP身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆