django-crispy-forms 是对django form在html页面呈现方式进行管理的一个第三方插件。

配置: 在INSTALLED_APPS中加入'crispy_forms'

django-crispy-forms可以选择四种css库,分别是bootstrap,bootstrap3,uni-from以及foundation,当你选定一种后,你需要在settings.py中设置,例如

CRISPY_TEMPLATE_PACK = 'bootstrap'

django-crispy-forms不再将静态的css以及js文件包括进来,需要自己去下载,并将其放入你的静态文件夹里。

一个model实例:

class MessageForm(forms.Form):
text_input = forms.CharField()
textarea = forms.CharField(
widget = forms.Textarea(),
)
radio_buttons = forms.ChoiceField(
choices = (
('option_one', "Option one is this and that be sure to include why it's great"),
('option_two', "Option two can is something else and selecting it will deselect option one")
),
widget = forms.RadioSelect,
initial = 'option_two',
)
checkboxes = forms.MultipleChoiceField(
choices = (
('option_one', "Option one is this and that be sure to include why it's great"),
('option_two', 'Option two can also be checked and included in form results'),
('option_three', 'Option three can yes, you guessed it also be checked and included in form results')
),
initial = 'option_one',
widget = forms.CheckboxSelectMultiple,
help_text = "<strong>Note:</strong> Labels surround all the options for much larger click areas and a more usable form.",
)
appended_text = forms.CharField(
help_text = "Here's more help text"
)
prepended_text = forms.CharField()

prepended_text_two = forms.CharField()
multicolon_select = forms.MultipleChoiceField(
choices = (('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5')),
)
helper = FormHelper()
helper.form_class = 'form-horizontal'
helper.layout = Layout(
Field('text_input', css_class='input-xlarge'),
Field('textarea', rows="3", css_class='input-xlarge'),
'radio_buttons',
Field('checkboxes', style="background: #FAFAFA; padding: 10px;"),
AppendedText('appended_text', '.00'),
PrependedText('prepended_text', '<input type="checkbox" checked="checked" value="" id="" name="">', active=True),
PrependedText('prepended_text_two', '@'),
'multicolon_select',
FormActions(
Submit('save_changes', 'Save changes', css_class="btn-primary"),
Submit('cancel', 'Cancel'),
)
)

在Html中使用:

{% load crispy_forms_tags %}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="/static/media/css/bootstrap.min.css" type="text/css">
<meta charset="UTF-8">
<title></title>
</head>
<body>
{% crispy form %}
</body>
</html>

效果图:

最新文章

  1. php之验证码小程序
  2. 关于CAShapeLayer的一些实用案例和技巧【转】
  3. JQ动画的简单介绍
  4. WebService 基础使用&amp;cxf第三方Service使用
  5. 重载赋值运算符 &amp;&amp; 对象
  6. mysql 我的学习
  7. HW5.28
  8. 使用C#在word中插入页眉页脚
  9. PHP学习系列(1)&mdash;&mdash;字符串处理函数(5)
  10. 【js 编程艺术】小制作四
  11. Sublime text3 设置的中文翻译
  12. CenOS 上安装 Redis 服务器
  13. 前后端分离与 restful api
  14. REST API设计指导——译自Microsoft REST API Guidelines(三)
  15. (75)Wangdao.com第十三天_JavaScript 包装对象
  16. Centos6.5下使用LAMP搭建discuz论坛(编译安装 PS :自学中 写的不好请见谅)
  17. Linux 小知识翻译 - 「UTC 和 JST」
  18. 【Dubbo 源码解析】03_Dubbo Protocol&amp;Filter
  19. A - 不要62
  20. Xilinx 7 series FPGA multiboot技术的使用

热门文章

  1. .NET study collection links
  2. mybatis一对一关联表查询
  3. LintCode-两数之和
  4. 使用RUBY生成二维码
  5. SQL中采用Newtonsoft.Json处理json字符串
  6. 【opengl】OpenGL中三维物体显示在二维屏幕上显示的变换过程
  7. hdoj 3549 Flow Problem(最大网络流)
  8. Flex 内置验证器—验证用户输入
  9. 通过SqlHelper实现登录
  10. win7 64位下如何安装配置mysql-5.7.4-m14-winx64