【发布时间】:2011-09-23 08:11:29
【问题描述】:
我的用例看起来很基本,但我在网上找不到任何东西!
这个想法是一个带有“我已阅读并同意条款和条件”复选框的表格 以及“条款和条件”上的链接,该链接指向包含此类条款和条件的页面...... 经典!
所以我的表单中有一个字段如下:
tos = forms.BooleanField(widget=forms.CheckboxInput(),
label=_(u'I have read and agree to the <a href="%s" target="_blank">terms and conditions</a>' % reverse('terms_of_use')),
initial=False)
“使用条款”是我在 urls.py 中的一种 url 模式的名称
但我得到一个错误:
ImproperlyConfigured: The included urlconf urls doesn't have any patterns in it
我的 urlconf 在整个站点上都可以正常工作,所以我认为问题是在呈现表单时 urlconf 尚未填充?
我尝试使用lazy_reverse = lazy(reverse, str) 而不是reverse,但它没有解决任何问题。
有没有办法使这项工作?用例看起来非常非常基本,所以肯定有一种方法可以做到这一点,而不必分解我模板中的表单?!
【问题讨论】:
-
猜猜:
reverse有一个current_appkwarg,也许它需要一个小方向来加载urls.py。 -
报错信息来源于:raise ImproperlyConfigured("The included urlconf %s doesn't have any patterns in it" % self.urlconf_name) 表示他知道?