Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
django,python-master->;细节_Python_Django - Fatal编程技术网

django,python-master->;细节

django,python-master->;细节,python,django,Python,Django,当我在djangoproject教程中按“主页-详细信息”中的链接(我将目录从poll更改为naslovnica)时,出现以下错误:找不到页面(404)/polls/1/: views.py: def app_index(request): latest_poll_list = Poll.objects.all()[:5] context = {'latest_poll_list': latest_poll_list} return render(request, 'na

当我在djangoproject教程中按“主页-详细信息”中的链接(我将目录从poll更改为naslovnica)时,出现以下错误:找不到页面(404)/polls/1/:

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})
这是URL.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)),
)

我不小心发现了问题所在。在index.html代码中:

{% if latest_poll_list %}
    <ul>
    {% for poll in latest_poll_list %}
        <li><a href="/poll/{{ poll.id }}/">{{ poll.question }}</a></li>
    {% endfor %}
    </ul>
{% else %}
    <p>No polls are available.</p>
{% endif %}
{%if-latest\u poll\u list%}
    {最新轮询列表%中的轮询百分比}
  • {%endfor%}
{%else%} 没有投票

{%endif%}
线

  • 应该是:

    <li><a href="/naslovnica/{{ poll.id }}/">{{ poll.question }}</a></li>
    

  • index.html和detail.html文件的内容是什么?好的。。。下一步。。。你的索引函数在哪里(你显示的是app_索引,而不是index),如果有不同的html文件,请包括它。请注意,我在这里没有看到任何“a href”链接;我原以为你没有重命名其中一个模板中的一个。这里是views.py:def index(request):now=datetime.datetime.now()version=django.get_version()html=“ovo je index od naslovnice”返回HttpResponse(html)如果有人能帮我编辑此答案以正确的方式显示代码,你可以用3个反勾(`)来包装代码在开始和结束处设置格式,或在每行开始处设置4个空格的缩进(在实际缩进代码之前)
    {% if latest_poll_list %}
        <ul>
        {% for poll in latest_poll_list %}
            <li><a href="/poll/{{ poll.id }}/">{{ poll.question }}</a></li>
        {% endfor %}
        </ul>
    {% else %}
        <p>No polls are available.</p>
    {% endif %}
    
    <li><a href="/poll/{{ poll.id }}/">{{ poll.question }}</a></li>
    
    <li><a href="/naslovnica/{{ poll.id }}/">{{ poll.question }}</a></li>