python - 如何在 Django 中通过 SOAP 使用数据库?

标签 python django soap django-models suds

目前我有一个 Django 项目,我们称之为后端。有一个文件夹 api,我使用 Django-Tastypie 声明了该资源:

from django.contrib.auth.models import User
from tastypie.resources import ModelResource, ALL
from tastypie.authentication import BasicAuthentication
from tastypie.authorization import DjangoAuthorization
from tastypie.cache import SimpleCache
from tastypie.throttle import CacheDBThrottle

class UserResource(ModelResource):
    class Meta:
        queryset = User.objects.all()
        resource_name = 'user'
        excludes = ['email', 'password', 'is_staff', 'is_superuser']
        authentication = BasicAuthentication()
        authorization = DjangoAuthorization()
        cache = SimpleCache()
        throttle = CacheDBThrottle()

        filtering = {
            'username' : ALL,
            'date_joined' : ['gt','lt','gte','lte','range']        
        }

有了正确的路由规则,如果我访问像 http://127.0.0.1:8000/api/v1/user?format=json 这样的 URL,我应该会返回一些json 格式的用户信息,但来 self 的本地数据库。我不想使用任何本地数据库,除了使用一些虚拟数据进行测试之外。我希望这样的 get 请求能够使用我登录 session 的用户名和密码向某个远程服务器发出 SOAP 请求。

我已经有一个独立的 Python 应用程序,我可以在其中执行 SOAP 请求并使用 SUDS 获取 SOAP 响应。和预先下载的 WSDL 文件。现在我想将此功能包含在我的 Dhango 项目中,方式是更改项目中 settings.py 中的设置,但不必修改项目内的应用程序。

最佳答案

您可以定义自己的Custom managers使用独立的 Python 应用程序。

关于python - 如何在 Django 中通过 SOAP 使用数据库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16174027/

相关文章:

python - 在 2D 列表中的特定索引处使用快速排序

python - 亚马逊cloudsearch无法使用boto添加文档?

python - 将 django-tables 的列自定义为下拉列表

python - 使用外键从另一个模型访问对象

django - 为什么 Django 函数 django.views.static.serve() 不安全?

ajax - Django request.is_ajax 返回 false

java - 在 SOAPUI 中创建 JDBC 连接

WCF SOAP 服务对于大型请求返回 Not Found,对于较小的请求工作正常

python - manage.py syncdb 无法创建 auth_user 表

magento - 错误WSDL:SOAP-错误:解析WSDL:无法从加载