【问题标题】:Not able to figure out why django can't reverse the URL无法弄清楚为什么 django 无法反转 URL
【发布时间】:2012-07-13 03:40:26
【问题描述】:

错误

Caught NoReverseMatch while rendering: Reverse for ''tazasabzii.tazasabzi.views.gallery'' with arguments '()' and keyword arguments '{}' not found.

urls.py

urlpatterns = patterns('tazasabzii.tazasabzi',

    (r'^tazasabzi/gallery/$', 'views.gallery'),

views.py

def gallery(request):
    z = {'title':'TazaSabzi.com',
         'heading':'TazaSabzi.com',
         'viewName':'gallery',}
    fruits = Sabji.objects.filter(kind__contains="fruit")
    sfruits = Sabji.objects.filter(kind__contains="special fruit")
    svegetables = Sabji.objects.filter(kind__contains="special vegetable")
    vegetables = Sabji.objects.filter(kind__contains="vegetable")
    soffers = Sabji.objects.filter(kind__contains="special offer")
    saari_sabzi = {'fruits':fruits,
                                            'vegetables':vegetables,
                                            'special fruits':sfruits,
                                            'special vegetables':svegetables,
                                            'special offers':soffers,}
    return render_to_response('gallery.html',{'tz':z,
                                              'saari_sabzi':saari_sabzi.iteritems(),},context_instance=RequestContext(request))

错误

154     <a target="_blank" href="{% url 'tazasabzii.tazasabzi.views.gallery' %}">
155     <div class="gallery button" style="width:100px;">
156     <div style="color:white; margin-top:5px;">Gallery</label>

【问题讨论】:

    标签: python django


    【解决方案1】:

    尝试类似&lt;a target="_blank" href="{% url 'appname.views.gallery' %}"&gt;

    使用named URLs

    可能您没有在主 url_conf 中包含应用程序 url

    【讨论】:

    • 阅读url tag的文档。
    • 是的,我已经尝试了所有可能的组合,它根本不起作用,同样的错误一次又一次
    • 删除视图名称周围的'。另一个常见错误是视图目录中缺少 _init_.py 文件...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-22
    • 2015-04-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多