LoginSignup
0
1

More than 1 year has passed since last update.

Django form_invalidでcontextを追加したい

Posted at

バリデーションが通らない時に特定の値をテンプレート側に渡したいということがありました。
日本語の情報がなかったので記事にしました

views.py
class HogeFormView(FormView):
    ....
    def form_invalid(self, form):
        context = self.get_context_data()
        context['hoge'] = "hoge"
        return self.render_to_response(context)

参考にしたサイト
Updating context data in FormView form_valid method?

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1