0
我正在嘗試爲命名的包裝方法做一個URL的反向解析。 我有以下我的urls.py設置(基於this answer:帶參數的命名包裝方法的反向URL
urlpatterns = patterns('',
('param_select/$',session_check(param_select),{}, 'param_select'),
('registration/$',registration),
('result_show/(\d+)',session_check(result_show),{}, 'result_show'),
('^expofit/$',media_clean(start),{}, 'start'),
('result_pick/$',session_check(result_pick),{}, 'result_pick'),
('mail_report/$',session_check(mail_report)),
('notification/$',session_check(notification)),
它爲所有的方法不帶參數但是它沒有在其中一個帶有參數
In [50]: from django.core.urlresolvers import reverse
In [51]: reverse('result_pick')
Out[51]: '/result_pick/'
In [52]: reverse('start')
Out[52]: '/expofit/'
In [53]: reverse('result_show', args=(2,))
---------------------------------------------------------------------------
NoReverseMatch Traceback (most recent call last)
/home/alan/Desktop/expofit/expofit_env/local/lib/python2.7/site-packages/django/core/management/commands/shell.pyc in <module>()
----> 1 reverse('result_show', args=(2,))
/home/alan/Desktop/expofit/expofit_env/local/lib/python2.7/site-packages/django/core/urlresolvers.pyc in reverse(viewname, urlconf, args, kwargs, prefix, current_app)
474 resolver = get_ns_resolver(ns_pattern, resolver)
475
--> 476 return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))
477
478 reverse_lazy = lazy(reverse, str)
/home/alan/Desktop/expofit/expofit_env/local/lib/python2.7/site-packages/django/core/urlresolvers.pyc in _reverse_with_prefix(self, lookup_view, _prefix, *args, **kwargs)
394 lookup_view_s = lookup_view
395 raise NoReverseMatch("Reverse for '%s' with arguments '%s' and keyword "
--> 396 "arguments '%s' not found." % (lookup_view_s, args, kwargs))
397
398 class LocaleRegexURLResolver(RegexURLResolver):
NoReverseMatch: Reverse for 'result_show' with arguments '(2,)' and keyword arguments '{}' not found.
我。一直以來,這本書,除了指定的url每個外觀看起來都是一樣的。想法的缺陷在哪裏?
剛剛檢查過,我一直在閱讀的文檔是針對Django 1.5的。升級到1.5後會更新 – TheMeaningfulEngineer 2013-03-12 14:28:47