Django不包括已安装的应用程序中的urls.py

时间:2011-07-02 17:23:34

标签: django django-urls django-apps

我收到以下错误:

Caught NoReverseMatch while rendering: Reverse for 'satchless-checkout-prepare-order' with arguments '()' and keyword arguments '{}' not found.

但我在已安装的应用中有satchless.contrib.checkout.commonsatchless.contrib.checkout.commonurls.py包含:

from django.conf.urls.defaults import patterns, url

from .views import confirmation, prepare_order, reactivate_order

urlpatterns = patterns('',
    url(r'^prepare/$', prepare_order, {'typ': 'satchless_cart'},
        name='satchless-checkout-prepare-order'),
    url(r'^(?P<order_token>\w+)/confirmation/$', confirmation,
        name='satchless-checkout-confirmation'),
    url(r'^(?P<order_token>\w+)/reactivate/$', reactivate_order,
        name='satchless-checkout-reactivate-order'),
)

为什么我无法从模板中拨打{% url satchless-checkout-prepare-order %}

2 个答案:

答案 0 :(得分:3)

您是否已从root urlconf中包含它?

你的主urls.py文件中有这样的东西:

url(r'^foo/' include('satchless.urls')),

答案 1 :(得分:2)

您不必在INSTALLED_APPS中加入satchless.contrib.checkout.common。它不是真正的应用程序,它是包含多步和单步检出应用程序的通用视图/装饰器的python包。

如果您查看satchless / contrib / checkout / multistep / urls.py或satchless / contrib / checkout / singlestep / urls.py,您可以看到两者都包含来自common / urls.py的模式:


from ..common.urls import urlpatterns

urlpatterns = urlpatterns + patterns('',
...

您需要做的是选择结帐方法(比方说多步),将其添加到INSTALLED_APPS并包含相应的网址:


settings.py:

INSTALLED_APPS = (
...
    'satchless.contrib.checkout.multistep',
...
)


urls.py:

urlpatterns = patterns(
...
    url('^checkout/', 'satchless.contrib.checkout.multistep.urls')
...
)