0
比方說,我有一個表單來創建一個動物(名稱,顏色...),如何訪問輸入值並在同一個表單頁面中顯示它(表單提交後)。如何使用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