pythondjangohtml5_如何在django表单中使用html5?

我想用这个片段# extra.py in yourproject/app/

from django.db.models import FileField

from django.forms import forms

from django.template.defaultfilters import filesizeformat

from django.utils.translation import ugettext_lazy as _

class ContentTypeRestrictedFileField(FileField):

"""

Same as FileField, but you can specify:

* content_types - list containing allowed content_types. Example: ['application/pdf', 'image/jpeg']

* max_upload_size - a number indicating the maximum file size allowed for upload.

2.5MB - 2621440

5MB - 5242880

10MB - 10485760

20MB - 20971520

50MB - 5242880

100MB 104857600

250MB - 214958080

500MB - 429916160

"""

def __init__(self, *args, **kwargs):

self.content_types = kwargs.pop("content_types")

self.max_upload_size = kwargs.pop("max_upload_size")

super(ContentTypeRestrictedFileField, self).__init__(*args, **kwargs)

def clean(self, *args, **kwargs):

data = super(ContentTypeRestrictedFileField, self).clean(*args, **kwargs)

file = data.file

content_type = file.content_type

if content_type in self.content_types:

if file._size > self.max_upload_size:

raise forms.ValidationError(_('Please keep filesize under %s. Current filesize %s') % (filesizeformat(self.max_upload_size), filesizeformat(file._size)))

else:

raise forms.ValidationError(_('Filetype not supported.'))

return data

用这个片段

^{pr2}$

所以我可以用html5检查文件的大小,如何将这两个片段合并成1?我还发现了一个java代码片段,可以上传视频并检查大小,但我找不到任何关于如何实现它的文档。我不能使用javascript,因为我不能信任客户机

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值