代码之家  ›  专栏  ›  技术社区  ›  Micah Pearce

djangorestframework-公共URL基下的所有API路径

  •  0
  • Micah Pearce  · 技术社区  · 7 年前

    Django 2.1、python 3.6、Djangorestframework

    是否可以创建一个包含多个模型的API路径?

    urlpatterns = [
       ...
        path('api/', include('cards.api.urls')),
        path('api2/', include('decks.api.urls')),
    ]
    
    urlpatterns = [
       ...
        path('api/', include('cards.api.urls', 'decks.api.urls')),
    ]
    

    我收到以下错误消息

    Specifying a namespace in include() without providing an app_name '
    django.core.exceptions.ImproperlyConfigured: Specifying a namespace in include() without providing an app_name is not supported. Set the app_name attribute in the included module, or pass a 2-tuple containing the list of patterns and app_name instead.
    

    我希望能够在一个URL下调用所有的API。

    1 回复  |  直到 7 年前
        1
  •  1
  •   JPG    7 年前

    只需使用,

    urlpatterns = [
       ...
        path('api/', include('cards.api.urls')),
        path('api/', include('decks.api.urls')),
    ]
    
    推荐文章