Tastypie-将参数附加到URI [英] Tastypie- Append parameters to URI

查看:74
本文介绍了Tastypie-将参数附加到URI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Django Deliciouspie中将参数附加到URL。

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

这里是url.py。

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),
)

我需要将 action_type = 1 传递到URL。我该怎么做?

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

推荐答案

您需要包含以下api URL:

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'

之后,您可以使用资源名称以其余方式访问任何资源。
您的情况是:'/ api / v1 / action_type / 1'

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'

所有内容均在 http://django-tastypie.readthedocs.org/en/latest/下进行了解释interacting.html

这篇关于Tastypie-将参数附加到URI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆