如何获取表单小部件以在自定义模板中呈现

时间:2019-07-02 22:07:00

标签: django

我正在尝试在HTML页面上呈现dJango表单小部件。

forms.py分配:

class MenuItemsFormBase(forms.Form):
    name = forms.CharField(max_length=200)

html作业:

<div class="col-sm-6 ce_name">
                <b>Name:</b><br/>
                {{ form.name }}
            </div>

查看:

class MenuManagerFormBaseView(DashboardPermissionsMixin, FormView):
pass

class EditComponentView(MenuManagerFormBaseView):
template_name = 'menu_manager/component_editor.html'
form_class = EditComponentForm
success_url = '/thanks/'

def get_form_kwargs(self, **kwargs):
    component_id = self.kwargs['component_id']
    component = Component()
    if component_id != '0':
        component = Component.objects.get(pk=component_id)
    ingredients = None
    if component.id is not None:
        ingredients = component.ingredients.all()
    component.name = 'boo'
    return {
        'parent_id': component.id is not None,
        'component': component,
        'ingredients': ingredients,
        'meal_id': self.kwargs['meal_id'],
        'containers': Packaging.objects.all()
    }

据我了解,这应该创建一个元素。而是呈现以下内容:

"                      Ricky                    "

我做错了什么,阻止了小部件的呈现?

0 个答案:

没有答案