对于某些例程,rest api基于unity资产服务器。

django-unity-asset-server-http-client的Python项目详细描述


https://badge.fury.io/py/django-unity-asset-server-http-client.svg

LICENSE

麻省理工学院

Requirements

  • python 2.7版
  • Django 1.6+
  • djangorestframework 2.4.3+
  • django过滤器0.8

Quick start

  1. 将“duashttp”添加到已安装的应用程序设置中,如下所示:

    INSTALLED_APPS = (
        ...
        'duashttp',
    )
    

2.在已安装的应用程序设置中添加Unity Asset服务器路由器并配置 访问Unity Asset服务器。

DATABASE_ROUTERS=['duashttp.router.UnityAssetServerRouter',]
DATABASES={'default':{'ENGINE':'django.db.backends.sqlite3','NAME':os.path.join(BASE_DIR,'db.sqlite3'),},'unity_asset_server':{'ENGINE':'django.db.backends.postgresql_psycopg2','NAME':'game_project_database_name','USER':'admin','PASSWORD':'admin_password','HOST':'192.168.0.1',# There UNITY asset server is placed on'PORT':'10733'# standard unity asset server port number}}

三。使用django restframe工作设置管理settings.py以 获得最佳配置:

REST_FRAMEWORK={'PAGINATE_BY':10,'PAGINATE_BY_PARAM':'page_size',# Maximum limit allowed when using `?page_size=xxx`.'MAX_PAGINATE_BY':100,'DEFAULT_AUTHENTICATION_CLASSES':('rest_framework.authentication.BasicAuthentication','rest_framework.authentication.SessionAuthentication',),'DEFAULT_FILTER_BACKENDS':('rest_framework.filters.DjangoFilterBackend',)}
    应用自定义视图集或使用存在,并将其包含在“URL.Py”中:
# -*- views.py -*-fromduashttp.views.apiimportAssetVersionViewSetBasefromrest_framework.decoratorsimportlist_routefromrest_framework.responseimportResponsefromdjango.db.modelsimportQclassAssetVersionViewSet(AssetVersionViewSetBase):""" AssetVersion view set """@list_route()defconfigs(self,request):"""get xml configs with their last revision"""qset=(Q(name__icontains='.xml')&~Q(name__icontains='(DEL_')&~Q(name__icontains='~$'))xml_docs=self.queryset.filter(qset).order_by('name','-revision').distinct('name')docs=self.filter_queryset(xml_docs)page=self.paginate_queryset(docs)serializer=self.get_pagination_serializer(page)returnResponse(serializer.data)
# -*- urls.py -*-fromdjango.conf.urlsimportpatterns,include,urlfromviewsimport*fromrest_frameworkimportroutersrouter=routers.DefaultRouter()router.register(r'asset_versions',AssetVersionViewSet)urlpatterns=patterns('',# Examples:url(r'^api/',include(router.urls)),url(r'^api/',include(router.urls,namespace='api')),)
  1. 启动开发服务器并访问http://127.0.0.1:8000/api/ 查看可用的api调用。

Models

您可以使用以下命令从Unity Asset Server(基于Posgres 8.3)获取数据:

>>>fromduashttp.modelsimportAssetVersion>>>versions=AssetVersion.objects.filter(name__icontains='Actions.xml')>>>versions...[<AssetVersion:Actions.xml[46]>,<AssetVersion:Actions.xml[45]>,...<AssetVersion:Actions.xml[44]>,<AssetVersion:Actions.xml[43]>,...<AssetVersion:Actions.xml[42]>,<AssetVersion:Actions.xml[41]>,...<AssetVersion:Actions.xml[40]>,<AssetVersion:Actions.xml[39]>,...<AssetVersion:Actions.xml[38]>,<AssetVersion:Actions.xml[37]>,...<AssetVersion:Actions.xml[36]>,<AssetVersion:Actions.xml[35]>,...<AssetVersion:Actions.xml[34]>,'...(remaining elements truncated)...']>>>version=versions.get(revision=45)>>>print(version.get_blob_data())...<?xmlversion="1.0"encoding="utf-8"?>...<DocumentElement>...<Data_Table>...<id>1</id>...<num>1</num>...<prefab_name/>...<small_prefab_name>SmallAction_gems_3_dollar</small_prefab_name>...<icon_sprite>lucky_gem</icon_sprite>...<is_small_action>1</is_small_action>...<is_big_action/>...<is_top_panel_action/>...<move_to_window/>...<affected_id/>...<appear_date>27/10/201408:00</appear_date>...<start_date>27/10/201408:00</start_date>...<end_date>31/10/201408:00</end_date>...<expire_date>31/10/201408:00</expire_date>...<source/>...<patch/>...<bind_id/>...</Data_Table>...</DocumentElement>

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java使用split函数分割字符串,但没有得到期望的结果   未找到包含derby数据库嵌入架构的sql Java桌面应用程序错误   java elasticsearch vs solr用于定制全文搜索系统   java Android:创建没有startOffset的动画延迟?   java如何查看其他应用程序接收的数据?   java如何在Linux中使用D和classpath选项运行jar文件   java和域设计最佳实践   具有相同内存位置的java数组,将显示为输出   连接到java中的elasticsearch?   Java Playframework重定向到带有Json负载的外部url   java无法在Android平台上使用InputStream为蓝牙socket创建ObjectInputStream   使用POI将Excel日期转换为Java日期,年份未正确显示   oracle从数据库层还是Java层调用webservice?