NoReverseMatch“”不是注册的名称空间

时间:2019-07-24 09:38:27

标签: django

大家好,我一直在努力将项目移至Anaconda的另一个位置,因此,在最终安装所有内容并设置了项目之后,我遇到了一些我不理解的错误。首先,我将代码放在应用程序内一个名为api的子文件夹中,其中包含视图,序列化程序和url。我加入了网址,但似乎什么也没发生。我将所有api文件移到了app文件夹,并删除了api文件夹。现在,我在/ op_data / objects /中收到此错误NoReverseMatch('api-op-data'不是注册的名称空间)。即使删除此网址后,我仍然会收到相同的错误。这是我的代码:

urls.py

from django.urls import path, re_path
from django.views.generic import TemplateView
from django.conf.urls import url, include
from django.contrib import admin
from djgeojson import views
from djgeojson.views import GeoJSONLayerView
from django.conf.urls.static import static
import MMA
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from MMA import views
from rest_framework_jwt import views
from rest_framework_jwt.views import obtain_jwt_token, refresh_jwt_token, verify_jwt_token

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^api/auth/token/$', obtain_jwt_token, name='api-auth-token'),
    url(r'^api/', include(('MMA.urls', 'api-op-data'), namespace='api-op-data')),
] 

urls.py

from django.conf.urls import url
from django.contrib import admin
from .views import OP_Data_RudView, OP_Data_ApiView, UserCreateAPIView, UserLoginAPIView, WoType_ApiView, WoType_RudView, UserObjects_ApiView, UserObjects_RudView


app_name = 'MMA'
urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^users/register/$', UserCreateAPIView.as_view(), name='register'),
    url(r'^users/login/$', UserLoginAPIView.as_view(), name='login'),
    url(r'^op_data/$', OP_Data_ApiView.as_view(), name='post-listcreate'),
    url(r'^op_data/(?P<pk>\d+)/$', OP_Data_RudView.as_view(), name='post-rud'),
    url(r'^op_data/wo_type/$', WoType_ApiView.as_view(), name='post-listcreate'),
    url(r'^op_data/wo_type/(?P<pk>\d+)/$', WoType_RudView.as_view(), name='post-rud'),
    url(r'^op_data/objects/$', UserObjects_ApiView.as_view(), name='post-listcreate'),
    url(r'^op_data/objects/(?P<pk>\d+)/$', UserObjects_RudView.as_view(), name='post-rud'),  

] 

错误日志:

NoReverseMatch at /op_data/objects/

'api-op-data' is not a registered namespace

Request Method:     GET
Request URL:    http://---.--.-.---:7000/op_data/objects/
Django Version:     2.0.6
Exception Type:     NoReverseMatch
Exception Value:    

'api-op-data' is not a registered namespace

Exception Location:     C:\Users\Administrator.HR-JUGOR\Anaconda3\envs\MMA\lib\site-packages\django\urls\base.py in reverse, line 86
Python Executable:  C:\Users\Administrator.HR-JUGOR\Anaconda3\envs\MMA\python.exe
Python Version:     3.6.5
Python Path:    

['C:\\Users\\Administrator.HR-JUGOR\\Anaconda3\\envs\\MMA\\Mobile',
 'C:\\Users\\Administrator.HR-JUGOR\\Anaconda3\\envs\\MMA\\python36.zip',
 'C:\\Users\\Administrator.HR-JUGOR\\Anaconda3\\envs\\MMA\\DLLs',
 'C:\\Users\\Administrator.HR-JUGOR\\Anaconda3\\envs\\MMA\\lib',
 'C:\\Users\\Administrator.HR-JUGOR\\Anaconda3\\envs\\MMA',
 'C:\\Users\\Administrator.HR-JUGOR\\Anaconda3\\envs\\MMA\\lib\\site-packages',
 'C:\\Users\\Administrator.HR-JUGOR\\Anaconda3\\envs\\MMA\\lib\\site-packages\\win32',
 'C:\\Users\\Administrator.HR-JUGOR\\Anaconda3\\envs\\MMA\\lib\\site-packages\\win32\\lib',
 'C:\\Users\\Administrator.HR-JUGOR\\Anaconda3\\envs\\MMA\\lib\\site-packages\\Pythonwin']

Server time:    Wed, 24 Jul 2019 09:49:27 +0000

1 个答案:

答案 0 :(得分:0)

tabBarController.selectedViewController = vc if let cell = vc.collectionView?.cellForItem(at: IndexPath(item: index, section: 0)) { alertVC.popoverPresentationController?.sourceView = cell alertVC.popoverPresentationController?.sourceRect = cell.bounds } // if statement gets ignored as cv is not yet loaded as it seems 不是/op_data/objects/的{​​{1}}的配置URL。

在这种情况下,命名空间参数似乎是多余的,您已经在post-listcreate之前将命名空间声明为api/op_data/objects/,并在以后显式地将其声明为'^api/',这基于以下原因:所提供的代码,尽管我需要查看您是如何从视图和模板访问这些URL的,以便确定。

您也不需要在MMA.urls中重新声明您的管理URL,我质疑您决定在根URL配置中包含include() URL,似乎它属于MMA.urls,并且'api-op-data'名称空间中的其他网址