On Sat, Apr 26, 2008 at 1:18 PM, python_fan <[EMAIL PROTECTED]> wrote:
> > > On Apr 26, 3:54 am, Kenneth Gonsalves <[EMAIL PROTECTED]> wrote: > > > or better still, please paste your full current view and template. > > Also it would be easier to handle the thread if you did not top post ;-) > > Ok, will do. :) > Here is the code: http://dpaste.com/47029/ upload_form = None upload_result = '' if request.method == 'POST': upload_form = FileUploadForm(request.POST, request.FILES) if upload_form.is_valid(): # get file name and contents from request: file_name = request.FILES['txt_file']['filename'] file_content=request.FILES['txt_file']['content'] # save the file. something like: f=open("C:\\" + file_name, 'w') f.writelines(file_content) f.close() else: upload_form = FileUploadForm() You've got the creation of the blank FileUploadForm nested in the else for if upload_form.is_valid(). So it appears you do not create a FileUploadForm when request.method is anything other than POST (unless there is more relevant code that follows this snippet). It looks like the else that you have should be un-dented one level, so that a blank FileUploadForm is generated for display when request.method is, say, GET. It's also normal to return an HttpResponseRedirect to a different page when is_valid() processing completes, which you don't seem to be doing. Finally nowhere in here do you set upload_result, which seems to be expected by your template. Your initial code seemed to be using that to display errors, which is not necessary if you go the normal route of re-displaying the invalid form (which will have error messages printed by each field that did not validate) when is_valid returns False. So perhaps you just want to remove the upload_result reference from your template. Karen --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---