本文介绍了切换case_class和template_name的大小写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为"foo"的会话变量.现在,我想根据'foo'的值在我的cbv中加载特定的表单和模板.因此,我需要将form_class和template_name放入切换用例中.

I have a session var with the name 'foo'.Now I would like, depending of the value of 'foo' load a specific form and template in my cbv. So I need to put form_class and template_name into a switch case.

哪个功能最合适?得到?get_form?看起来没有什么是真的合适的地方.

Which function is the right place for this? get? get_form? looks like nothing is really the right place for this.

有人建议或其他方式吗?:)

Anyone a suggestion or knows another way? :)

推荐答案

CBV资源管理器是您的朋友: http://ccbv.co.uk/projects/Django/1.5/django.views.generic.edit/CreateView/

CBV explorer is your friend: http://ccbv.co.uk/projects/Django/1.5/django.views.generic.edit/CreateView/

您需要覆盖

def get_form_class(self):

def get_template_names(self):

这篇关于切换case_class和template_name的大小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 01:19