使用参数'('',)'和关键字参数'{}'找不到“结果”。尝试了1种模式:['民意调查/(?P <album_id> [0-9] +)/结果/ $']

时间:2016-11-01 16:47:33

标签: python html django

我试图为相册创建一个URL,但却感到沮丧

所以我得到这个错误(我是编程的新手)

Reverse for 'results' with arguments '('',)' and keyword arguments '{}' not found. 1 pattern(s) tried: ['polls/(?P<Album_id>[0-9]+)/results/$']

在这一行

<h1><a href="{% url 'polls:results' Album.id %}">{{ album.AlbumTitle }}</a></h1>

继承了view.py文件

from django.shortcuts import get_object_or_404, render
from django.http import HttpResponse
from django.http import Http404
from django.template import loader
from django.shortcuts import get_object_or_404, render

from .models import Artist


def index(request):
    latest_Artist_list = Artist.objects.order_by('id')[:5]
    context = {'latest_Artist_list': latest_Artist_list,}
    return render(request, 'polls/index.html', context)


def detail(request, Artist_id):
    global Artist
    artist = get_object_or_404(Artist, pk=Artist_id)         #kazkodel mazoji
    return render(request, 'polls/detail.html', {'Artist': artist}) #kazkodel mazoji

def results(request, Album_id):
    #global Album
    album = get_object_or_404(Album, pk=Album_id)
    return render(request, 'polls/results.html', {'Album': album})

继承人url.py文件

from django.conf.urls import url

from . import views

app_name = 'polls'

urlpatterns = [
    url(r'^$', views.index, name='index'),
    url(r'^(?P<Artist_id>[0-9]+)/$', views.detail, name='detail'),
    url(r'^(?P<Album_id>[0-9]+)/results/$', views.results, name='results'),
]

1 个答案:

答案 0 :(得分:1)

它似乎是空的,因为你正在使用专辑而它只是专辑。尝试使用:

<a href="{% url 'polls:results' album.id %}">

而不是:

<a href="{% url 'polls:results' Album.id %}">

(抱歉我的英文)

相关问题