Monday, April 27, 2015

Re: model.FileField

You can save the file wherever you like, just change the file path where you are writing the file to make use of settings.MEDIA_ROOT rather than a hard-coded URL.

Since you aren't using a model, Django is assuming you want to do something fancy with the file, so you are responsible for doing the heavy lifting for operations such as writing it to disk.

One or more of these packages may also help:

https://www.djangopackages.com/grids/g/file-managers/

-James

On Apr 27, 2015 6:17 AM, "mangu rajpurohit" <rajpurohitmangu@gmail.com> wrote:
Hi James,

Thanks for suggesting me the page at location  https://docs.djangoproject.com/en/1.8/topics/http/file-uploads/. I visited that page and as you suggested, there was no need of database in between, However, I noted that we have to manually write the file as shown in snippet given below(copied from url suggested by you)

def handle_uploaded_file(f):      with open('some/file/name.txt', 'wb+') as destination:          for chunk in f.chunks():              destination.write(chunk)

So, I mean, Isn't there any way through which this file writing operation takes places automatically in django. Moreover, you note that here, filepath is hard-coded. I want that it file uploaded by user, must be copied at MEDIA_ROOT variable set in settings.py of project.
 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9b9e962d-84a4-4344-b0a1-452623ac0db4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2Be%2BciW2bt83d6U7KxCEgs%2BLvoO%3DAQFiq8MZguKWUmRWc9gpiw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment