I have a script which reads data from a csv file. I need to store the data into a database which has already been created as
$ python manage.py syncdb
so, that automated data entry is possible in an easier manner, as available in the django shell.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You have to set up a django environment to use in your script, afterwards your python script can work with django models just as in the ‘real’ site:
The easiest way to do this: set the DJANGO_SETTINGS_MODULE environment variable (e.g.
export DJANGO_SETTINGS_MODULE=mysite.settings). Then your script can do things like:There are also some other ways, where you have to write some additional code in your script, I prefer these because they do not require an environment variable:
1) setup_environ:
2) Create settings on the flow: