On Sep 18, 7:35 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> Better to set the upload filesize limit on your server eg Apache's has
> a directive for max file size. Otherwise the file will be uploaded and
> checked anyway.

If using mod_python, the Apache LimitRequestBody directive doesn't
work entirely properly. See:

  https://issues.apache.org/jira/browse/MODPYTHON-240

End result is that instead of returning an 413 error, it suffers a
failure and generates a 500 error instead.

If using mod_wsgi however it will do the correct thing and return a
413 response. Because this check is done before the WSGI application
is even called, the Apache error page responses are used. If however
you have specified ErrorDocument directive for a 413 error to direct
to Django, you could instead have Django produce just the error page
at least.

So, another reason to use mod_wsgi over mod_python. :-)

Graham

> If you want to report an error to the user you could use validation on
> the form. The code below returns a error if a file extension is not
> allowed.
>
> from django import forms
> from os.path import splitext
> from django.utils.translation import gettext as _
>
> class VideoField(forms.FileField):
>     default_error_messages = {'invalid_video': _(u"Please upload
> a .wmv , .mov, .mp4 or .3pg"),}
>
>     def clean(self, data, initial=None):
>         f = super(VideoField, self).clean(data, initial)
>         if f is None:
>             return None
>         elif not data and initial:
>             return initial
>         file_exts = ('.mp4', '.mov', '.wmv', '.3gp',)
>         if not splitext(f.name)[1].lower() in file_exts:
>              raise
> forms.ValidationError(self.error_messages['invalid_video'])
>         return f
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to