Tastypie- Append parameters to URI

这一生的挚爱 提交于 2019-12-20 05:41:13

问题


How do I append parameters to a URL in Django Tastypie.

Here is url.py.

from modules.actions.views import InstallationResource,ApiActionsResource
from tastypie.api import Api
from modules.actions import views
v1_api = Api(api_name='v1')
v1_api.register(ApiActionsResource())

urlpatterns = patterns('',
    url(r'^(?P<action_type>.+)', views.ApiActionsResource.as_view),
)

I need to pass action_type=1 to the URL. How do I do it?


回答1:


You need to include your api urls like this:

urlpatterns = patterns(''`,
    (r'^api/', include(v1_api.urls)),
)

Make sure that you've set your resource name:

class ApiActionsResource(Resource):

    class Meta:
        resource_name = 'action_type'

After that, you can access any resourse in a rest way, using the resource name. In your case that would be: '/api/v1/action_type/1'

It's all explained under http://django-tastypie.readthedocs.org/en/latest/interacting.html.



来源:https://stackoverflow.com/questions/21531628/tastypie-append-parameters-to-uri

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!