Django REST Framework with Django 2.0プロジェクト、つまりurl(r'^something/' ...
がpath(something/ ...
に置き換えられました。
rest_framework
パターンの設定方法を理解しようとしています。
これは私が持っているものです:
router = routers.DefaultRouter()
router.register(r'regulations', api.RegulationViewSet)
router.register(r'languages', api.LanguageViewSet)
urlpatterns = [
...
path('api-auth/', include('rest_framework.urls', namespace='rest_framework')),
...
]
http://127.0.0.1:8000/regulations
にアクセスすると、次のようになります。
ページが見つかりません(404)
urlpatterns
はどのように設定すればよいですか?
_urlpatterns = [
...
path('', include(router.urls)),
path('api-auth/', include('rest_framework.urls', namespace='rest_framework')),
...
]
_
path('', include(router.urls)),
を使用すると、以下を取得できます。
_http://127.0.0.1:8000/regulations/
http://127.0.0.1:8000/languages/
_
と
_path('api-auth/', include('rest_framework.urls', namespace='rest_framework')),
_
得られる:
_http://127.0.0.1:8000/api-auth/{other paths}
_
router
を登録したら、それをurlpatterns
に含める必要があります。 @Ykhが提案した方法は技術的には正しいですが、コンテンツに関しては要点がありません。
urlpatterns = [
# here you include your router
path('', include(router.urls)),
# here you include the authentication paths
path('api-auth/', include('rest_framework.urls', namespace='rest_framework')),
]
これで、次のルートができます。
http://localhost:8000/regulations/
http://localhost:8000/languages/
プラス:
http://localhost:8000/api-auth/{other paths}