如何修复“在没有提供app_name的情况下在include()中指定名称空间”

时间:2019-10-31 09:05:42

标签: django rest django-rest-framework django-urls

我正面临在包含的模块中设置app_name属性的问题。尽管我已经看到了如何解决它的类似答案,但是我没有找到适合我的方法。

这是我的urls.py

self.chatList = querySnapshot!.documents.map{$0.documentID}

我试图声明一个app_name变量

from django.conf.urls import url,include
from django.contrib import admin
from intranet import views,forms
from django.contrib.auth import views as auth_views
from django.conf import settings
from rest_framework import routers
from django.conf.urls.static import static
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.urls import reverse


router = routers.DefaultRouter()
router.register(r'pharmakeia', views.PharmakeiaViewSet,base_name='pharmakeia')
router.register(r'doctors', views.DoctorsViewSet,base_name='doctors')
router.register(r'new-pharmakeia', views.VriskoViewSet,base_name='new-pharmakeia')
router.register(r'new-all-pharmakeia', views.VriskoAllViewSet,base_name='new-all-pharmakeia')
 views.json_data,base_name='test_pharmakeia')


urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^rest/', include(router.urls, namespace='rest')),
    url(r'^api-auth/', include(rest_framework.urls, namespace='rest_framework')),

,然后修复包含如下所示的包含功能的网址

app_name="intranet"

尽管我已经定义了rooter,但我面临一个新问题“ ModuleNotFoundError:没有名为'router'的模块”

这是我在命令行中的输出

url(r'^rest/', include((router.urls,app_name), namespace='rest')),
url(r'^api-auth/', include(('rest_framework.urls',app_name), namespace='rest_framework')),

有什么解决方法吗?

0 个答案:

没有答案