django、django rest frameworkを使ってAPIを作成しています。
APIのURIが、
/api/recommends/cf-products?userId=1
となっているので、下記のように指定しましたが、404エラーとなり困っています。
どのように指定すれば良いか教えていただけないでしょうか?
urls.py
python
1from django.urls import path, re_path 2from api import views 3 4urlpatterns = [ 5 path('users', views.UserSelectAPIView.as_view()), 6 re_path(r'^recommends/cf-products/(?P<userId>\d+)/$', views.RecommendSelectAPIView.as_view()), 7]
エラー内容抜粋
Using the URLconf defined in config.urls, Django tried these URL patterns, in this order:
api/ ^recommends/cf-products/(?P<userId>\d+)/$
The current path, api/recommends/cf-products, didn't match any of these.
You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.
使用しているバージョン
django = "==2.2"
djangorestframework = "==3.9.2"
python_version = "3.7"
なお、ご質問いただきましてが、cf-products/(?の/を除いて、
re_path(r'^recommends/cf-products(?P<userId>\d+)/$', views.RecommendSelectAPIView.as_view())
/api/recommends/cf-products?userId=1
でアクセスしたところ、同様に下記のエラーとなりました。
Using the URLconf defined in config.urls, Django tried these URL patterns, in this order:
api/ ^recommends/cf-products(?P<userId>\d+)/$
The current path, api/recommends/cf-products, didn't match any of these.
You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.
よろしくお願いいたします。
あなたの回答
tips
プレビュー