0

在我的 Django 代码中,我正在编写一个connection.py,它将使用以下内容连接到另一台服务器http_auth = http_auth.HTTPBasicAuth(user password)。因此,当我连接到该服务器时,我传递的参数之一是http_auth = http_auth.HTTPBasicAuth(user password)针对服务器。我在网上搜索了很多和 Django 文档,但没有确切告诉我该怎么做?谁能帮忙

4

1 回答 1

1

Here is an example of how you might use Django's Basic Authentication when presenting Users as RESTful resources:

# REST endpoint for authenticating user accounts
class UserResource(ModelResource):

    class Meta:
        queryset = User.objects.all()
        resource_name = 'auth/user'
        authentication = BasicAuthentication()
        authorization = DjangoAuthorization()

    def apply_authorization_limits(self, request, object_list):
        return object_list.filter(username=request.user)

Authentication can be as simple as the one line:

        authentication = BasicAuthentication()

depending on how you implement it.

于 2012-10-19T03:37:53.627 回答