【问题标题】:Django isn't including the urls.py from an installed appDjango 不包含已安装应用程序中的 urls.py
【发布时间】:2011-09-27 08:38:22
【问题描述】:

我收到以下错误:

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

但我安装的应用程序中有satchless.contrib.checkout.common。在satchless.contrib.checkout.common 内是一个urls.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 %}

【问题讨论】:

    标签: django django-urls django-apps


    【解决方案1】:

    你是否从你的根 urlconf 中包含了它?

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

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

    【讨论】:

    • 哇,我不知道我是怎么错过的。谢谢。
    【解决方案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 并包含适当的 url:

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

    【讨论】:

      猜你喜欢
      • 2013-08-10
      • 2017-05-25
      • 2020-03-07
      • 2012-01-31
      • 2013-03-18
      • 1970-01-01
      • 1970-01-01
      • 2017-05-13
      • 2020-10-02
      相关资源
      最近更新 更多