本文介绍了如何将内联CSS应用于Django表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个Django项目。我在Django中创建了一个基于类的视图形式,并且显示了如何给该表单的样式表? {{form.as_p}} 显示,但是如何设计该表单?

解决方案

说你有一个modelform,你可以添加类和样式到字段如下:

  class SomeModelNameForm forms.ModelForm):
name = forms.CharField(widget = forms.TextInput(attrs = {'class':'form-control input-area','placeholder':'输入你的名字}}) = True)
credentials = forms.CharField(widget = forms.TextInput(attrs = {'class':'form-control input-area','placeholder':'输入你的指定'}),required = True )

class Meta:
model = SomeModelName

对于任何表单类型



文档中的Django表单小部件:


I am doing a Django project. I made a class-based view form in Django and it's shown but how to give stylesheet to that form? It's shown by {{ form.as_p }}, but how to design that form?

解决方案

Say you have a modelform, you can add classes and styles to fields as follows:

class SomeModelNameForm(forms.ModelForm):
    name = forms.CharField(widget=forms.TextInput(attrs={'class': 'form-control input-area', 'placeholder': 'Enter your name'}), required=True)
    credentials = forms.CharField(widget=forms.TextInput(attrs={'class': 'form-control input-area', 'placeholder': 'Enter your designation'}), required=True)

    class Meta:
        model = SomeModelName

This works for any form type

Django Form widgets in the documentation: https://docs.djangoproject.com/en/dev/ref/forms/widgets/

这篇关于如何将内联CSS应用于Django表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 11:56