我正在創建一個簡單的python
API,其中有兩個應用程序,名爲snippets
和polls
。對於我的API的單一入口點,我使用DefaultRouter
類而不是基於常規功能的視圖和@api_view
裝飾器。DefaultRouter類不爲Python中的所有應用程序創建API根視圖
正如Djando Rest Framework Tutorial是
的defaultrouter中類自動創建API根視圖
我有在API根查看問題說明。這裏是我的Snippets' urls.py
router = DefaultRouter()
router.register(r'snippets', views.SnippetViewSet)
router.register(r'users', views.UserViewSet)
urlpatterns = [
url(r'^', include(router.urls)),
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))
]
這是我polls' urls.py
router = DefaultRouter()
router.register(r'actors', views.ActorViewSet)
urlpatterns = [
url(r'^', include(router.urls)),
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))
]
我root urls.py
是如下
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^', include('snippets.urls')),
url(r'^', include('polls.urls')),
url(r'^api-auth/', include('rest_framework.urls',
namespace='rest_framework')),
]
現在,當我開始在瀏覽器服務器和負載應用程序,那隻能說明片段網址作爲這樣的入口點(民意調查的網址缺失)
,如果改變我的根urls.py
像這樣(先加polls.urls然後snippets.urls)
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^', include('polls.urls')),
url(r'^', include('snippets.urls')),
url(r'^api-auth/', include('rest_framework.urls',
namespace='rest_framework')),
]
現在它顯示投票的URL(丟失片段的URL)
但我希望這兩個應用程序的Url在那裏。我不知道我在這裏錯過了什麼。任何形式的幫助將不勝感激。