1

I'm starting out with DRF and ran into some trouble when trying to set up a simple APIView.

This is the view:

class SongSearchView(views.APIView):
    def get(self, request, query, format=None):
        return Response(['Justin Bieber - Boyfriend', 'Justin Timberlake - My Love'])

and these are the URL patterns:

router = DefaultRouter()

urlpatterns = patterns('',
                   url(r'^api/song_search/(?P<query>[a-zA-Z0-9\w]+)/$', views.SongSearchView.as_view()),
                   url(r'^admin/', include(admin.site.urls)),
                   url(r'^api/', include(router.urls)),
                   url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),
                   url(r'^$', views.index, name='index'),
)

and when I try to access http://127.0.0.1:8000/api/song_search/?query=justin I get a

Page not found (404)
Request Method: GET
Request URL:    http://127.0.0.1:8000/api/song_search/?query=justin

What is the issue? :(

1 Answer 1

4

Your Url pattern Regular expression is wrong.. If you still want to stick to your current url pattern , I suggest you change your request url from http://127.0.0.1:8000/api/song_search/?query=justin to http://127.0.0.1:8000/api/song_search/justin

Sign up to request clarification or add additional context in comments.

1 Comment

Oh of course, confused the regular expression with GET parameters.. Thank you!

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.