django报错: NoReverseMatch at / 'devops' is not a registered namespace

页面请求信息如下:
Request Method: GET
Request URL:  http://127.0.0.1:8000/
Django Version: 1.11.5
Exception Type: NoReverseMatch
Exception Value:  
'devops' is not a registered namespace
Exception Location: C:\Users\Administrator\AppData\Roaming\Python\Python35\site-packages\django\urls\base.py in reverse, line 87
Python Executable:  D:\Python35\python.exe
Python Version: 3.5.3


代码报错会出现(第87行):
  机房管理


两种解决方法
(1)在devops/urls.py中修改(不推荐)
#urls.py.url 下添加一个app_name就好:
from . import views
app_name = 'ops'
urlpatterns = [
   url(r'^idc/$', idc.as_view(), name="idc"),
]

(2)在根urls中修改(比如官方文档就是mysite.urls) 
加了个namespace

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^ops/', include("apps.devops.urls",namespace="ops")),
    url(r'^$', IndexView.as_view(), name="index"),
]

你可能感兴趣的:(django)