У меня есть файл destributor.csv который нужно выгрузить в модель БД.
Есть скрипт он называется import_csv.py
Я запускаю его следующей командой из директории скрипта :
../../../manage.py import_csv "/home/webuser/fcprj/media/destributor.csv"
выводится ошибка:
Traceback (most recent call last):
File "../../../manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/home/webuser/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/home/webuser/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/webuser/venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 294, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/webuser/venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 345, in execute
output = self.handle(*args, **options)
File "/home/webuser/fcprj/fcapp/management/commands/import_csv.py", line 31, in handle
emp.save()
File "/home/webuser/fcprj/fcapp/models/distributor.py", line 170, in save
super(Distributor, self).save(*args, **kwargs)
File "/home/webuser/venv/local/lib/python2.7/site-packages/django/db/models/base.py", line 796, in save
force_update=force_update, update_fields=update_fields)
File "/home/webuser/venv/local/lib/python2.7/site-packages/django/db/models/base.py", line 833, in save_base
update_fields=update_fields, raw=raw, using=using)
File "/home/webuser/venv/local/lib/python2.7/site-packages/django/dispatch/dispatcher.py", line 191, in send
response = receiver(signal=self, sender=sender, **named)
File "/home/webuser/fcprj/fcapp/models/__init__.py", line 155, in distributor_post_save
args=[instance.id.hex],
File "/home/webuser/venv/local/lib/python2.7/site-packages/templated_email/__init__.py", line 67, in send_templated_mail
headers=headers, **kwargs)
File "/home/webuser/venv/local/lib/python2.7/site-packages/templated_email/backends/vanilla_django.py", line 180, in send
e.send(fail_silently)
File "/home/webuser/venv/local/lib/python2.7/site-packages/django/core/mail/message.py", line 342, in send
return self.get_connection(fail_silently).send_messages([self])
File "/home/webuser/venv/local/lib/python2.7/site-packages/django_uwsgi/mail.py", line 11, in send_messages
if self._send(email_message):
File "/home/webuser/venv/local/lib/python2.7/site-packages/django_uwsgi/mail.py", line 16, in _send
from .task import send_mail
File "/home/webuser/venv/local/lib/python2.7/site-packages/django_uwsgi/task.py", line 4, in <module>
from .decorators import spool
File "/home/webuser/venv/local/lib/python2.7/site-packages/django_uwsgi/decorators.py", line 17, in <module>
raise ImportError("uWSGI is not available")
ImportError: uWSGI is not available
Код скрипта:
# -*- coding: utf-8 -*-
from django.core.management.base import BaseCommand, CommandError
from fcapp.models import Distributor
import csv
class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument('csv_file', nargs='+', type=str)
def handle(self, *args, **options):
for csv_file in options['csv_file']:
dataReader = csv.reader(open(csv_file), delimiter=';', quotechar='"')
for row in dataReader:
emp = Distributor()
emp.name = row[0]
emp.full_name = row[0]
#print(row[0])
emp.address = row[1]
emp.phone = '{0} {1}'.format(row[2],row[3])
emp.email = row[4]
emp.site = row[5]
#emp.api_key= 'uniqkey'
emp.language = 'ru'
emp.api_key_status='inactive'
emp.api_key_end_date_0 = '12.12.2016'
emp.api_key_end_date_1 = '14:12:05'
emp.api_requests_available = 0
emp.turnover = 0
emp.coef = 1.40
emp.save()
print(emp.name + 'save')
#self.stdout.write(
# 'Created distributor {}'.format(emp.name)
#)
Нашёл вроде ответы, но всё равно что-то не доходит как пофиксить эту ошибку
https://stackoverflow.com/questions/18417823/how-d...
https://stackoverflow.com/questions/8241680/django...
Я так понял нужно что-то прописать в виртуальном окружении, но что и куда, не могу разобраться.
Проблема возникает именно в этой строчке:
emp.save()