Help us understand the problem. What is going on with this article?

Django2 公式チュートリアルのPollsアプリの機能追加【pollsの削除】

More than 1 year has passed since last update.

前提

views.pyに削除機能を追加

polls/views.py
class DeleteView(generic.DeleteView):
    model = Question
    form_class = QuestionForm

    success_url = reverse_lazy('polls:index')

    def delete(self, request, *args, **kwargs):
        result = super().delete(request, *args, **kwargs)
        messages.success(
            self.request, '「{}」を削除しました'.format(self.object))
        return result

urls.pyに削除のURLを追加

polls/urls.py
    path('<int:pk>/delete/',views.DeleteView.as_view(), name='delete'),

question_confirm_delete.htmlを追加

templates/polls/question_confirm_delete.html
<p>{{ object }} を削除していいですか?</p>
<form method="post">
  <button>削除する</button>
  {% csrf_token %}
</form>

detail.htmlに削除ボタンを追加

templates/polls/detail.html
<a href="{% url 'polls:delete' question.id %}">削除</a>

これで動くと思います。
動かない場合は、当記事冒頭の前提条件を確認してください。

aksuzuki
Python/Djangoを使ってWebアプリの開発をしています。 Techpitで教材をリリースしました。 「【Django】財務分析アプリを作ってみよう!」 https://www.techpit.jp/p/django-accounting Python/Djangoだけでなく、Chart.js、Datatables(jQuery)、財務会計も学べる一石四鳥の教材です!
https://vancreworth.com/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした