0

在页面上运行 django 应用程序时出现以下错误

"partner/buzzfeed/": NoReverseMatch at /partner/BuzzFeed/ Reverse for 'video_player' with arguments '('BuzzFeed', 'fXkqhhIlOtA', 'NY Yankees: 6 Essential Pieces of Postseason Memorabilia')' and keyword arguments '{}' not found.

看起来正确的变量是从模板传递的,但没有与 url 正确匹配(我认为)。关于如何解决它的任何建议?

视图.py

def partner_channel(request,partner_name):
    file = urllib2.urlopen('http://gdata.youtube.com/feeds/api/users/'+partner_name+'/uploads?v=2&max-results=50')
    data = file.read()
    file.close()        
    root = etree.fromstring(data)       
    entries = root.findall('{http://www.w3.org/2005/Atom}entry')        
    feed=[]
    i=0 #for feed list tracking
    for entry in entries:
        #find media:group
        media = entry.find('{http://search.yahoo.com/mrss/}group')      
        #get description, title, thumbnail
        desc = media.find('{http://search.yahoo.com/mrss/}description').text
        title = media.find('{http://search.yahoo.com/mrss/}title').text
        thumbnail = media.find('{http://search.yahoo.com/mrss/}thumbnail[2]').attrib.get("url")
        video = media.find('{http://gdata.youtube.com/schemas/2007}videoid').text
        author = entry.find('{http://www.w3.org/2005/Atom}author').find('{http://www.w3.org/2005/Atom}name').text
        feed.append([i,title, desc, thumbnail, video, author, url])     
        i=i+1       
    return render_to_response('reserve/templates/partner.html', {'feed':feed},
        context_instance=RequestContext(request))

def video_player(request,author,video,title):   
    return render_to_response('reserve/templates/video_player.html', {'author':author, 'video':video, 'title':title},
        context_instance=RequestContext(request))

模板

{% for video in feed %}    
    <a href="{% url video_player feed.1.5 video.4 video.1   %}" >Link</a>
{% endfor %}

网址.py

urlpatterns = patterns('reserve.views',
    url(r'^partner/(?P<partner_name>[-\w]+)/$', 'partner_channel'),
    url(r'^partner/(?P<author>[-\w]+)/(?P<video>[-\w]+)/(?P<video_title>[-\w]+)/$', 'video_player'),
    url(r'^partner/(?P<author>[-\w]+)/(?P<video>\w+)/(?P<title>\w+)/$', 'video_player'),
)
4

1 回答 1

0

您可以执行以下两项操作之一:

在模板中,更改

{% url video_player feed.1.5 video.4 video.1 %}

{% url reserve.views.video_player feed.1.5 video.4 video.1 %}

或者:

为网址添加名称:

url(r'^partner/(?P<author>[-\w]+)/(?P<video>[-\w]+)/(?P<video_title>[-\w]+)/$', 'video_player', name="video-player"),

并将模板调用更改为

{% url video-player feed.1.5 video.4 video.1 %}

于 2012-10-10T14:44:29.793 回答