我试图在我的自定义小部件的django表单定义中使用django的reverse()函数,但遇到一个错误:ImproperlyConfigured
The included urlconf urls doesn't have any patterns in it
代码如下:
^{pr2}$
我很确定,我的works.url'的配置正确,因为所有其他页都按预期工作。在
有什么原因,为什么我不能在表单定义中使用reverse()?它是否与此代码运行时有关?有没有办法解决这个问题,或者这里唯一的选择就是硬编码URL?在
以下是完整的错误转储:Environment:
Request Method: GET
Request URL: http://127.0.0.1:8000/works/add?category=1&subcategory=1
Django Version: 1.4 pre-alpha
Python Version: 2.7.1
Installed Applications:
['django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.admindocs',
'social_auth',
'sorl.thumbnail',
'helpers',
'users',
'works',
'debug_toolbar']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.transaction.TransactionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware')
Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
89. response = middleware_method(request)
File "/usr/local/lib/python2.7/dist-packages/django/middleware/common.py" in process_request
67. if (not _is_valid_path(request.path_info, urlconf) and
File "/usr/local/lib/python2.7/dist-packages/django/middleware/common.py" in _is_valid_path
164. urlresolvers.resolve(path, urlconf)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in resolve
416. return get_resolver(urlconf).resolve(path)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in resolve
298. for pattern in self.url_patterns:
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in url_patterns
328. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in urlconf_module
323. self._urlconf_module = import_module(self.urlconf_name)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py" in import_module
35. __import__(name)
File "/var/www/megenius/trunk/urls.py" in
27. url(r'^works/', include('works.urls')),
File "/usr/local/lib/python2.7/dist-packages/django/conf/urls/__init__.py" in include
24. urlconf_module = import_module(urlconf_module)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py" in import_module
35. __import__(name)
File "/var/www/megenius/trunk/works/urls.py" in
2. from works.views import *
File "/var/www/megenius/trunk/works/views.py" in
9. from works.forms import WorkForm
File "/var/www/megenius/trunk/works/forms.py" in
10. class WorkForm(forms.Form):
File "/var/www/megenius/trunk/works/forms.py" in WorkForm
31. data_source_url=reverse('works-json-categories'),
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in reverse
473. (prefix, resolver.reverse(view, *args, **kwargs)))
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in reverse
360. possibilities = self.reverse_dict.getlist(lookup_view)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in reverse_dict
276. self._populate()
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in _populate
242. for pattern in reversed(self.url_patterns):
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in url_patterns
332. raise ImproperlyConfigured("The included urlconf %s doesn't have any patterns in it" % self.urlconf_name)
Exception Type: ImproperlyConfigured at /works/add
Exception Value: The included urlconf urls doesn't have any patterns in it