1
我有一個模板,顯示發言人名稱列表,我想要點擊這些網址並進入發言者頁面,我通過一個唯一的ID看起來是這樣的 「832fc2ca-787f-484B-B815-f82959607311」,問題是,我得到的錯誤Django有一個意想不到的關鍵字參數'id_speaker'
get_speaker_by_id()得到了一個意想不到的關鍵字參數 'id_speaker'
我覺得問題在urls.py或speakers.html href中是ether。我看着每一個相關的問題,但我無法提交解決方案。
urls.py
url(r'^speakers', views.speakers_list, name='speakers'),
url(r'^speaker/(?P<id_speaker>[0-9a-z\-]+)/$',
views.get_speaker_by_id, name='get_speaker_by_id_url')
這是是揚聲器名稱的列表
speakers.html
{% for speaker in all_speakers_list%}
<div class="container">
<div class="row">
<div class="col-sm-6">
<a href="{% url 'get_speaker_by_id_url' speaker.speaker_id %}">{{ speaker.greek_name }}</a>
</div>
</div>
</div>
{% endfor %}
views.py
get_speaker_by_id(request, id_speaker):
''' Get speaker info by id '''
requested_speaker = Speaker.objects.get(speaker_id=id_speaker)
template = loader.get_template('greekparliament/speaker.html')
context = {
'requested_speaker': requested_speaker
}
return HttpResponse(template.render(context, request))
模型模板.py
class Speaker(models.Model):
speaker_id = models.CharField(max_length=200, default='')
english_name = models.CharField(max_length=200, default='', blank=True)
image = models.CharField(max_length=200, default='', blank=True)
email = models.EmailField(max_length=254, default='', blank=True)
wiki_el = models.URLField(max_length=200, default='', blank=True)
twitter = models.URLField(max_length=200, default='', blank=True)
greek_name = models.CharField(max_length=200, default='')
wiki_en = models.URLField(max_length=200, default='', blank=True)
website = models.URLField(max_length=200, default='', blank=True)
你可以確定你還沒有在views.py文件中多次定義'get_speaker_by_id()'嗎?您可能有多次定義'get_speaker_by_id()'的可能性,並且在第二次您沒有定義任何'id_speaker'參數 –
是的!我不相信我犯了這個錯誤。非常感謝你。也許發佈您的這個答案,以便我可以將其標記爲解決方案? – kpapadop