Len*_*rt- 7 django django-piston tastypie
我们将我们的API从Django - Piston移植到Django-TastyPie.一切顺利,'直到我们达到这个目的:
应用程序的urls.py
url(r'^upload/', Resource(UploadHandler, authentication=KeyAuthentication()), name="api-upload"),
url(r'^result/(?P<uuid>[^//]+)/', Resource(ResultsHandler, authentication=KeyAuthentication()), name="api-result")
Run Code Online (Sandbox Code Playgroud)
这使用活塞,所以我们想把它改成适合TastyPie的东西
url(r'^upload/', include(upload_handler.urls), name="api-upload"),
url(r'^result/(?P<uuid>[^//]+)/', include(results_handler.urls), name="api-result")
Run Code Online (Sandbox Code Playgroud)
但我们坚持这个错误
使用参数'()'和关键字参数'{'uuid':'fbe7f421-b911-11e0-b721-001f5bf19720'}'找不到'api-result'.
和结果的调试页面:
使用MelodyService.urls中定义的URLconf,Django按以下顺序尝试了这些URL模式:
^ melotranscript/^ upload/^ melotranscript/^ result /(?P [^ //] +)/ ^(?Presultshandler)/ $ [name ='api_dispatch_list'] ^ melotranscript/^ result /(?P [^ // ] +)/ ^(?Presultshandler)/ schema/$ [name ='api_get_schema'] ^ melotranscript/^ result /(?P [^ //] +)/ ^(?Presultshandler)/ set /(?P\w [\ w /; - ]*)/ $ [name ='api_get_multiple'] ^ melotranscript/^ result /(?P [^ //] +)/ ^(?Presultshandler)/(?P\w [\ w/- ]*)/ $ [name ='api_dispatch_detail'] ^ melotranscript/^ processed /(?P.)$ ^ admin/doc/^ TOU/$ [name ='TOU'] ^ $ [name ='index'] ^ admin/^ doc /(?P.)$当前的URL,melotranscript/result/fbe7f421-b911-11e0-b721-001f5bf19720 /,与这些中的任何一个都不匹配.
有谁知道这个问题?这可能是一个非常愚蠢/无聊的问题......
Mik*_*yan 35
对于遇到此问题的未来访问者,URL的名称是api_dispatch_list,您还需要指定API名称:
url = reverse('api_dispatch_list', kwargs={'resource_name': 'myresource', 'api_name': 'v1'})
Run Code Online (Sandbox Code Playgroud)
Tastypie还提供了其他URL名称:
/schema/ --> api_get_schema
/set/ --> api_get_multiple
/$your-id/ --> api_dispatch_detail
Run Code Online (Sandbox Code Playgroud)
您可以在调用中使用它们进行反转,您可以在HTML中使用它们,如下所示:
{% url "api_get_schema" resource_name="myresource" api_name="v1" %}
Run Code Online (Sandbox Code Playgroud)
小智 3
Django“include”不支持名称。您可以在https://github.com/toastdriven/django-tastypie/blob/master/tastypie/resources.py中找到 Tastypie 网址的名称:Resource.base_urls()
| 归档时间: |
|
| 查看次数: |
6056 次 |
| 最近记录: |