Thanks a lot Carole and Todd your posts have been very helpful to me,
I've managed to upload a file !!!, but I have a little problem now, I
would like to see if any of you or somebody else who reads this can
help me, the thing issue is : I can upload small files good, but when
it comes to bigger files, lets say 10M, the development server fails
with a long error traceback saying something about "socket.py in read
data = self._sock.recv(recv_size)"

the code Im using is this:

template for uploading:

{% extends "base.html" %}

{% block title %}
Uploading File.
{% endblock %}

{% block content%}

<p>
<form name="login" method="post" action="/uploading/"
enctype="multipart/form-data">


        <strong>Please enter the file you want to upload:</strong><br />
        {{ form.file }} {{ form.file_file }}
<input type="submit" name="submit" value="Upload!" / >
</form>
<br /><br />
Currently uploading to c:\Upload
</p>
{% endblock %}

the model:

class FileUpload(models.Model):
    file = models.FileField(upload_to='C:/Uploads')
    uptime = models.DateTimeField()
    class Admin:
        list_display = ("uptime", "file")

    def __str__(self):
        return self.hwkfile

and the views:

def uploadfile(request):
        manipulator = FileUpload.AddManipulator()

        if request.POST:
        # New upload if data was POSTed.
                new_data = request.POST.copy()
                new_data.update(request.FILES)

                new_data['uptime_date'] = datetime.date.today().isoformat()
                new_data['uptime_time'] = strftime("%H:%M", localtime())

                errors  = manipulator.get_validation_errors(new_data)
                print(errors)
                if not errors:
                # No errors found.
                        manipulator.do_html2python(new_data)
                        manipulator.save(new_data)
                        success = "File uploaded"
                        return render_to_response('success.html', {'success':
success})

                else:
                # Errors found, not writing to database.
                        errorstring = "<br />".join(errors)
                        return render_to_response('uploadfail.html', 
{'errorstring':
errorstring})
                        errors = new_data = {}  # Errors sent to the template, 
can be
cleared.
        else:
        # No data POSTed, redirect to /alfin
                return HttpResponseRedirect("/hwk")


def upload(request):
        manipulator = FileUpload.AddManipulator()
        form = forms.FormWrapper(manipulator,{},{})
        return render_to_response('upbin.html', {'form': form} )

Thanks for your help :)



--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

  • Re: Please Gerard M

Reply via email to