问题
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