basic http authentication with django-piston

孤人 提交于 2019-12-12 18:41:53

问题


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

回答1:


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

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



来源:https://stackoverflow.com/questions/3297125/basic-http-authentication-with-django-piston

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!