Django 1.6:发送电子邮件时出错

时间:2014-07-30 11:45:15

标签: python django email

我正在尝试实现忘记密码并正在测试它是否从python shell发送电子邮件,但我收到以下错误

django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_FROM_EMAIL, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

以下是settings.py

中的相关代码
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'something@gmail.com'
EMAIL_HOST_PASSWORD = 'blahblah'

DEFAULT_FROM_EMAIL = 'somthing@gmail.com'
SERVER_EMAIL =  'something@gmail.com'

2 个答案:

答案 0 :(得分:1)

您似乎正在使用命令python运行python shell。因此DJANGO_SETTINGS_MODULE变量不可用。使用

运行特定于应用程序的python shell
python manage.py shell

详细了解manage.py

  

manage.py设置DJANGO_SETTINGS_MODULE环境变量,使其指向项目的settings.py文件。

答案 1 :(得分:0)

不要尝试通过启动Python shell在Django中做任何事情。始终manage.py shell