I'm using a CustomUploadHandler for one of my views, but the form is always invalid - also request.FILES is also blank ? I'm a bit new to django, so not entirely sure whats going on
## form class UploadMidletPairForm(ModelForm): class Meta: model = MidletPair ### uploadhandler class CustomUploadHandler(FileUploadHandler): def __init__(self, request = None, upload_to = tempfile.gettempdir ()): self.upload_to = upload_to FileUploadHandler.__init__(self, request) def new_file(self, field_name, file_name, content_type, content_length, charset=None): #if not is_valid_upload(file_name): # here you can use a function to filter uploaded files. # raise UploadFileException , "forbidden file type" if not os.path.exists(self.upload_to): os.makedirs(self.upload_to) elif not os.path.isdir(self.upload_to): raise IOError("%s exists and is not a directory." % self.upload_to) outPath = os.path.join(self.upload_to, file_name) self.destination = open(outPath, 'wb+') FileUploadHandler.new_file(self, field_name, file_name, content_type, content_length, charset) def receive_data_chunk(self, raw_data, start): self.destination.write(raw_data) def file_complete(self, file_size): self.destination.close() ### view @login_required def validate_build(request): ''' Jad/Jar upload form ''' # Save the file to disk print >> sys.stderr, request.user request.upload_handlers = [CustomUploadHandler(upload_to = os.path.join(settings.MEDIA_ROOT, 'superglu', 'userdata', str (request.user), 'validate'))] UPLOAD_FORM_TITLE = 'Validate Build' if request.method == 'POST': form = UploadMidletPairForm(request.POST, request.FILES) if form.is_valid(): print >> sys.stderr, 'is valid' jad = request.FILES['jad_file'] jar = request.FILES['jad_file'] else: print >> sys.stderr, 'is not valid' print >> sys.stderr, form.errors else: form = UploadMidletPairForm() return render_to_response('validate/build/index.html', context_instance = RequestContext(request,\ { 'form': form, 'title': UPLOAD_FORM_TITLE, })) ### template {% extends "base.html" %} {% load i18n %} {% block breadcrumbs %} <div class="breadcrumbs"> <a href="../">{% trans 'Home' %}</a> › <a href="/validate/">Validate builds</a> › <a href="/validate/">Build</a> › </div> {% endblock %} {% block content %} <div id="content-main"> {% if perms.validate %} <h2>Upload Jad/Jar pair</h2> <form action="." method="post" enctype="multipart/form-data"> <fieldset> {% if form.image.errors %} <ul class="errorlist"> {% for error in form.image.errors %} <li>{{ error|safe }}</li> {% endfor %} </ul> {% endif %} {{ form }} </fieldset> <input type="submit" value="Validate" /> </form> {% else %} Sorry, your user is not enabled for validation {% endif %} </div> {% endblock %} --~--~---------~--~----~------------~-------~--~----~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---