プロジェクトにDjangoRedditスタイルの投票を実装しようとしています。私は過去数日間、それを実現する方法をつなぎ合わせようとしてインターネットを検索してきましたが、処理するようにurlconfを設定する方法とconfirm_vote.html
、そのファイルの内容が不明です。クリックして投票したときに発生するエラーは次のとおりです。
Generic vote view must be called with either post_vote_redirect, a
"next" parameter in the request, or the object being voted on must
define a get_absolute_url method or property.
これは、Django-Votingsのコードのこの部分に対応します。Githubページにリストされているサンプルプロジェクトとほぼ同じようにプロジェクトを設定しました。
私はconfirm_vote.htmlページを設定する必要があることを認識し、それに対処するためにurlconfを設定する方法を見つけるために多くの検索を行いました。このブログ投稿を見つけましたが、私の質問に答えていないようです。
誰かがconfirm_vote.htmlとそれに対処するためのURL正規表現に何を入れるべきかを理解するのを手伝ってもらえますか?助けてくれてありがとう!
編集
実際、confirm_vote.htmlのurlconfがサンプルチュートリアルにあることに気づきました。
(r'^links/(?P<object_id>\d+)/(?P<direction>up|down|clear)vote/?$',
vote_on_object, dict(model=Link, template_object_name='link',
template_name='kb/link_confirm_vote.html',
allow_xmlhttprequest=True)),
しかし、それでもアイデアとありがとうAttributeError
の内容について混乱しています!confirm_vote.html.
編集:link_list.html
url(r'^links/?$', object_list, dict(queryset=Link.objects.all(),
template_object_name='link', template_name='links/link_list.html',
paginate_by=15, allow_empty=True)),
{% for link in link_list %}<tr class="{% cycle odd,even %}">
<td class="vote">
{% dict_entry_for_item link from vote_dict as vote %}
{% dict_entry_for_item link from score_dict as score %}
<form class="linkvote" id="linkup{{ link.id }}" action="/links/{{ link.id }}/{% if vote and vote.is_upvote %}clear{% else %}up{% endif %}vote/" method="POST">
<input type="image" id="linkuparrow{{ link.id }}" src="{{ MEDIA_URL }}img/aup{% if vote and vote.is_upvote %}mod{% else %}grey{% endif %}.png">
{% csrf_token %}
</form>
<form class="linkvote" id="linkdown{{ link.id }}" action="/links/{{ link.id }}/{% if vote and vote.is_downvote %}clear{% else %}down{% endif %}vote/" method="POST">
<input type="image" id="linkdownarrow{{ link.id }}" src="{{ MEDIA_URL }}img/adown{% if vote and vote.is_downvote %}mod{% else %}grey{% endif %}.png">
{% csrf_token %}
</form>
</td>