On Thu, Feb 13, 2014 at 4:11 PM, simone monteleone <ares.a...@gmail.com>wrote:
> Hi all, > > I have to send a file (ex. csv file) to the Django server. > > I think to use the requests python module. > > Is this the best way? > The "best" way will depend on your exact requirements - I'll come back to this in a moment. However, Requests will certainly make it easy to write a Python script that will send a file to a Django server. > Second question; Django can receive this file? > If it can be sent over HTTP, Django can receive it. > And also in this case, what it is the best way? > Django's file handling documentation contains details on how to set up this sort of thing: https://docs.djangoproject.com/en/1.6/topics/http/file-uploads/ My goal is to load the csv file information in the dabatase handles by > django, > We need to be clear about your needs here. Do you actually need to do this over HTTP? I.e., you may want the data to be put into your database, but is there actually a requirement to upload that file? Could you just load the file onto the database directly? Django contains a bunch of tools for uploading files directly, without going through a web interface. Look into loaddata management command for details. https://docs.djangoproject.com/en/1.6/ref/django-admin/ There isn't a native CSV importer, but there are a couple floating around the web that you might be able to use. The other approach - just write the data directly to the database. Write some code to read the CSV file, and use Django's model objects to write the data directly; e.g., if you've got a model called MyModel, with two fields field1 and field2: MyModel.objects.create(field1=value1, field2=value2) will create a record in the database with those values. Yours, Russ Magee %-) -- 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+unsubscr...@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/CAJxq84-ZUP0Qkeseo337q545dwd65FNvjGarK9nwO40Jw048fQ%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.