Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django:如何正确使用urlresolvers?(已获取NoReverseMatch异常)_Python_Django - Fatal编程技术网

Python Django:如何正确使用urlresolvers?(已获取NoReverseMatch异常)

Python Django:如何正确使用urlresolvers?(已获取NoReverseMatch异常),python,django,Python,Django,我从Django项目中得到了一个NoReverseMatch异常,我不知道为什么 以下是我的项目布局: project openstack_dashboard mydashboard formpanel urls.py views.py 在URL.py中,我指定了以下URL模式: from django.conf.urls import patterns # noqa from django.conf

我从Django项目中得到了一个NoReverseMatch异常,我不知道为什么

以下是我的项目布局:

project
   openstack_dashboard
       mydashboard
          formpanel
             urls.py
             views.py
在URL.py中,我指定了以下URL模式:

from django.conf.urls import patterns  # noqa
from django.conf.urls import url  # noqa

from .views import IndexView, CreateView

urlpatterns = patterns('',
   url(r'^$', IndexView.as_view(), name='index'),
   url(r'^create$', CreateView.as_view(), name="temp_create")
)
在views.py中,我像往常一样指定了视图,因此将跳过

当我尝试从CreateView反转URL时,我得到了NoReverseMatch错误:

from openstack_dashboard.dashboards.mydashboard.formpanel.views import CreateView
from django.core.urlresolvers import reverse

reverse(CreateView)   # NoReverseMatch exception
reverse("temp_create") # NoReverseMatch exception
以下是完整堆栈跟踪(反向(CreateView):

反向(CreateView) 回溯(最近一次呼叫最后一次): 文件“”,第1行,在 文件“/usr/local/lib/python2.7/dist packages/django/core/urlresolvers.py”,第536行,相反 将iri_返回到_uri(解析器。_使用_前缀反向_(视图,前缀,*args,**kwargs)) 文件“/usr/local/lib/python2.7/dist packages/django/core/urlresolvers.py”,第456行,带前缀 (查找\视图\参数、kwargs、len(模式)、模式) NoReverseMatch:找不到参数为“()”且关键字参数为“{}”的“openstack_dashboard.dashboards.mydashboard.formpanel.views.CreateView”的反向。已尝试0个模式:[] 我错过什么了吗


谢谢

什么是完整的stacktrace?更新为full stacktraceFirst,我相信
reverse
在传递视图时会接受一个可调用对象,因此您需要说
CreateView.as_view()
,因为它是基于类的视图。这是你的根URL.py吗?您是否忘记在根urlconf中包含此应用程序的模式?请同时显示包含此模式的主URL.py。
>>> reverse(CreateView)
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py", line 536, in reverse
return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py", line 456, in          _reverse_with_prefix
(lookup_view_s, args, kwargs, len(patterns), patterns))
NoReverseMatch: Reverse for 'openstack_dashboard.dashboards.mydashboard.formpanel.views.CreateView' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []