功能描述:

学生可以对相应学校机构进行投诉建议.

form表单

  1. class SuggestForm(forms.Form):
  2. TYPE_CHOICES = (
  3. (0, u'学校'),
  4. (1, u'学院'),
  5. (2, u'校院'),
  6. )
  7. content = forms.CharField(label=u"内容", required=True, widget=forms.Textarea(attrs={'cols': 33}),
  8. error_messages={'required': u'请留下你的建议哦'})
  9. type = forms.ChoiceField(label=u"类型", required=True, widget=forms.RadioSelect, choices=TYPE_CHOICES,
  10. error_messages={'required': u'请做出你的选择哦'})
  11. error_messages = {
  12. 'content': {
  13. 'required': "内容不能为空哦"
  14. },
  15. }
  16.  
  17. def save(self, user, commit=True):
  18. cleaned_data = super(SuggestForm, self).clean()
  19. student = Student.objects.get(user=user)
  20. complain = Complain(student=student, content=cleaned_data.get("content"))
  21. complain.save()

前台显示

  1. <form action="" method="post">
  2. {% csrf_token %}
  3. {{ form.as_table }}
  4. <input type="submit" value="提交" class="ahref"/>
  5. </form>

view定义

  1. from django.views.generic import FormView
    class SuggestView(FormView):
  2.  
  3. template_name = "student/suggest.html"
  4. form_class = SuggestForm
  5.  
  6. def form_valid(self, form):
  7. form.save(self.request.user)
  8. return render(self.request, self.template_name, {"success": u"提交建议成功"})
  1. #===如果需要变更样式, 或者变更显示中文名称.更改 label
  2. def __init__(self, *args, **kwargs):
  3. super(TestModelForm, self).__init__(*args, **kwargs)
  4. #====改变样式,也可以赋值 class=???,在外面html页面上先定义好,个人不推荐直接在代码里写,只是为了演示。
  5. self.fields['yourname'].widget.attrs.update({'style' : 'border:1px dashed #ccc;'})
  6. self.fields['email'].label='伊妹儿'

FormView用法的更多相关文章

  1. EditText 基本用法

    title: EditText 基本用法 tags: EditText,编辑框,输入框 --- EditText介绍: EditText 在开发中也是经常用到的控件,也是一个比较必要的组件,可以说它是 ...

  2. jquery插件的用法之cookie 插件

    一.使用cookie 插件 插件官方网站下载地址:http://plugins.jquery.com/cookie/ cookie 插件的用法比较简单,直接粘贴下面代码示例: //生成一个cookie ...

  3. Java中的Socket的用法

                                   Java中的Socket的用法 Java中的Socket分为普通的Socket和NioSocket. 普通Socket的用法 Java中的 ...

  4. [转载]C#中MessageBox.Show用法以及VB.NET中MsgBox用法

    一.C#中MessageBox.Show用法 MessageBox.Show (String) 显示具有指定文本的消息框. 由 .NET Compact Framework 支持. MessageBo ...

  5. python enumerate 用法

    A new built-in function, enumerate() , will make certain loops a bit clearer. enumerate(thing) , whe ...

  6. [转载]Jquery中$.get(),$.post(),$.ajax(),$.getJSON()的用法总结

    本文对Jquery中$.get(),$.post(),$.ajax(),$.getJSON()的用法进行了详细的总结,需要的朋友可以参考下,希望对大家有所帮助. 详细解读Jquery各Ajax函数: ...

  7. 【JavaScript】innerHTML、innerText和outerHTML的用法区别

    用法: <div id="test">   <span style="color:red">test1</span> tes ...

  8. chattr用法

    [root@localhost tmp]# umask 0022 一.chattr用法 1.创建空文件attrtest,然后删除,提示无法删除,因为有隐藏文件 [root@localhost tmp] ...

  9. 萌新笔记——vim命令“=”、“d”、“y”的用法(结合光标移动命令,一些场合会非常方便)

    vim有许多命令,网上搜有一堆贴子.文章列举出各种功能的命令. 对于"="."d"."y",我在无意中发现了它们所具有的相同的一些用法,先举 ...

随机推荐

  1. HelloX项目github协同开发指南

    概述 为了提高协同开发效率,HelloX项目已托管到github网站上.根据目前的开发进展,创建了下列几个子项目: HelloX操作系统内核项目:https://github.com/hellox-p ...

  2. iOS开发中,应用内直接跳转到Appstore

    iOS开发中,应用内直接跳转到Appstore 1.进入appstore中指定的应用NSString *str = [NSString stringWithFormat:                ...

  3. golang printf

    1:  打印包括字段在内的实例的完整信息 同 %+V fmt.Printf("Hello world! %v","hufeng") 输出:Hello world ...

  4. MVC5.0 中如何提高Controller 的优先级

    //在area下建立的Home namespace WebApplication8.Areas.Weather.Controllers { public class HomeController : ...

  5. SQL Server索引进阶:第七级,过滤的索引

    原文地址: Stairway to SQL Server Indexes: Level 7,Filtered Indexes 本文是SQL Server索引进阶系列(Stairway to SQL S ...

  6. spring 加载配置文件的相关配置总结

    PropertyPlaceholderConfigurer      注意: Spring容器仅允许最多定义一个PropertyPlaceholderConfigurer(或<context:p ...

  7. HDU2008-数值统计

    描述: 统计给定的n个实数中,负数.零和正数的个数. 代码: #include<stdio.h> #include<string.h> #include<iostream ...

  8. 5.4.3 RegExp构造函数属性

    RegExp构造函数包含一些属性(这些属性在其他语言中被看成是静态属性).这些属性适用于作用域中的所有正则表达式,并且基于所执行的最近一次正则表达式操作而变化.关于这些属性的另一个独特之处,就是可以通 ...

  9. 加密PHP文件的方式,目测这样可以写个DLL来加密了

    <?php function encode_file_contents($filename) { $type=strtolower(substr(strrchr($filename,'.'),1 ...

  10. win7 资源管理器的背景色修改

    主要参考 http://blog.sina.com.cn/s/blog_49c182c20100w3nb.html win7 通过dll修改背景色首先找到这个文件C:\Windows\Resource ...