1

I am new to django rest framework. I was wondering what will be the url pattern if I want to implement a GET api which has query params as key-value pairs. Something like this:

http://example.com/getResource?userid=<userid>&resourceid=<resourceid>

Could not find anything like this in django documentation. Please advise.

Thanks

2
  • The url looks correct. What's the problem? Commented May 11, 2014 at 7:45
  • No problem with url, I wanted to know what will be the url pattern for such an api in urls.py file for django rest framework. Thanks. Commented May 11, 2014 at 7:58

1 Answer 1

5

For GET requests in Django (in general), you don't need to specify the parameters in the url pattern. In your urls.py, you simply write:

 url(r'^getResource$', 'app.views.view_function')

If your request url is (as in your example):

 http://example.com/getResource?userid=<userid>&resourceid=<resourceid>

You just get the values in the view function as follows:

 userid = request.GET['userid']
 resourceid = request.GET['resourceid']

If you're asking specifically about the django-rest-framework app, the docs (http://www.django-rest-framework.org/tutorial/quickstart) say your urls.py should be:

urlpatterns = patterns('',
    url(r'^', include(router.urls)),
    url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))
)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.