django,python - master - >详情

时间:2014-03-10 15:38:29

标签: python django

我收到此错误:找不到页面(404)/民意调查/ 1 /当我按下djangoproject教程中的主 - 详细信息页面链接时(我将目录从民意调更改为naslovnica):

views.py:

def app_index(request):
    latest_poll_list = Poll.objects.all()[:5]
    context = {'latest_poll_list': latest_poll_list}
    return render(request, 'naslovnica/index.html', context)

def detail(request, poll_id):
    try:
        poll = Poll.objects.get(pk=poll_id)
    except naslovnica.DoesNotExist:
        raise Http404
    return render(request, 'naslovnica/detail.html', {'poll': poll})

这是urls.py:

urlpatterns = patterns('',
    # Example:
    url(r'^$', 'naslovnica.views.app_index'),
    url(r'^naslovnica$', 'naslovnica.views.index'),
    url(r'^naslovnica/(?P<poll_id>\d+)/$', 'naslovnica.views.detail'),
    url(r'^naslovnica/(?P<poll_id>\d+)/results/$', 'naslovnica.views.results'),
    url(r'^naslovnica/(?P<poll_id>\d+)/vote/$', 'naslovnica.views.vote'),


    # Uncomment the admin/doc line below to enable admin documentation:
    # (r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
    (r'^admin/', include(admin.site.urls)),
)

有人可以用简单的语言解释为什么django正在寻找“民意调查”目录吗? django(1.6)中主/详细页面的机制是什么?

编辑:index.html的比赛(此页面显示为corectly)

{%if latest_poll_list%}     

        {%in latest_poll_list%}         
  • {{poll.question}}
  •     {%endfor%}     
{%else%}     

没有民意调查。

{%endif%}

detail.html:

{{轮询}}

1 个答案:

答案 0 :(得分:0)

我不小心发现了什么问题。在index.html代码中: {% if latest_poll_list %}

    {% for poll in latest_poll_list %}
  • {{ poll.question }}
  • {% endfor %}
{% else %}

No polls are available.

{% endif %}
线
  • {{ poll.question }}
  • 应该:
  • {{ poll.question }}