Recently I downloaded a US zip code data file in comma separated (CSV) format. Below are the steps and python script that I used to import that data into a django model for my site Wantbox.com.
The Steps to Import CSV Data into Django:
- Create your django model (mine is called “ZipCode”, see below).
- Create a python script called “load_data.py” with your correct django project and directory info (see mine below).
- Put the CSV file and “load_data.py†script in the same directory.
- From that directory run:
python ./load_data.pyâ€
That’s it. For a CSV file with about 42,000 rows this import took about 15 seconds. You can verify that the data loaded correctly by checking your django admin.
Recent Comments