動物(名前、色など)を作成するフォーム、入力フォームにアクセスしてフォームを送信した後に同じフォームページに表示する方法があるとします。フォームの入力値にアクセスする方法Djangoを使用してCreateView?
私が試した:
class AnimalCreate(CreateView):
model = Animal
form_class = AnimalForm
success_url = 'main_site/success.html'
def get_context_data(self, **kwargs):
color = ?? # how to get the value of the color input ?
context = super(AnimalCreate, self).get_context_data(**kwargs)
context['color'] = color
return context