我一直有这个python Django错误

时间:2014-09-24 00:14:59

标签: python django email settings

我使用以下python代码使用Django发送电子邮件:

from django.core.mail import EmailMessage

 csvfile=StringIO.StringIO()
          csvwriter=csv.writer(csvfile)
          for l in my_list:
                csvwriter.writerow(l)

          now=datetime.datetime.now()
          datestr=now.strftime("%Y%m%d")
          message=EmailMessage( subject="good codes", body="your codes are all good",from_email="natasha.che@fox.com",to=["natasha.che@fox.com"])
          message.attach("good_codes_{}.csv".format(datestr),csvfile.getvalue(),'text/csv')
          message.send()

我一直收到错误:

Traceback (most recent call last):
  File "dece2.py", line 166, in <module>
    csv_dict_test(my_list)
  File "dece2.py", line 145, in csv_dict_test
    message.send()
  File "/home/ubuntu/django-trunk/django/core/mail/message.py", line 283, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "/home/ubuntu/django-trunk/django/core/mail/message.py", line 244, in get_connection
    self.connection = get_connection(fail_silently=fail_silently)
  File "/home/ubuntu/django-trunk/django/core/mail/__init__.py", line 37, in     get_connection
    klass = import_string(backend or settings.EMAIL_BACKEND)
  File "/home/ubuntu/django-trunk/django/conf/__init__.py", line 46, in __getattr__
    self._setup(name)
  File "/home/ubuntu/django-trunk/django/conf/__init__.py", line 40, in _setup
    % (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting EMAIL_BACKEND, but settings are not configured. You must either define the environment variable     DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

我想知道如何修复它,如果我想设置设置,我应该在这里使用的设置名称。我是说真名。感谢

0 个答案:

没有答案