本文介绍了如何在Django 2中注册DRF路由器URL模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的DRF路由器指定一个名称空间,以便我可以时指定了c $ c> namespace kwarg code>。由DRF网址路由器构造网址格式时,指定 app_name 的正确方法是什么?我认为

You need to put app_name = 'x' in your application's url.py file. This is a little buried in the documentation:
https://docs.djangoproject.com/en/2.0/topics/http/urls/#id5

例如,如果在 /project/project/urls.py 您具有:

path('', include('app.urls', namespace='app'))

然后在相应的url文件中(在 /project/app/urls.py 中),您需要使用以下参数指定 app_name 参数:

Then in the corresponding url file (in /project/app/urls.py) you need to specify the app_name parameter with:

app_name = 'app'  #the weird code
urlpatterns = [
    path('', views.index, name = 'index'), #this can be anything
]

这篇关于如何在Django 2中注册DRF路由器URL模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 15:31