问题
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