[英]“ImportError: No module named sendgrid” for SendGrid in Google App Engine
[英]ImportError: No module named Mail python sendgrid
User.views.py這是我啟動本地開發服務器時Mail / views.py im的文件夾
from Mail.views import sendgrid_mail
content['url'] = input_values["host"] + "/EmailVerification/" +
user.email + '/' + md5_key
message = render_to_string('accountverification.html', content)
# sendMail.delay("[GavaGives] Account created successfully", message,
content['email'])
sendgrid_mail('info', user.email, '[GavaGives] Account created
successfully', message, 'user_offline_donation')
return response("create", "success", [])
Mail.views.py
def sendgrid_mail(from_email, to_email, subject, content, template):
sg = sendgrid.SendGridClient(config('SENDGRID_API_KEY'))
mail = sendgrid.Mail()
mail.add_to(to_email)
mail.set_from(mail_from(from_email))
mail.set_subject(subject)
mail.set_html(content)
mail.add_filter('templates', 'enable', '1')
mail.add_filter('templates', 'template_id', get_templates(template))
sg.send(mail)
Settings.py這是我啟動本地開發服務器時主項目/ settings.py im的文件夾
INSTALLED_APPS = [
'django.contrib.sessions',
'corsheaders', # CORS installation
'django_cron', # celery
'django_crontab', # Cron jobs
'celery',
'djcelery',
'Users',
'Campaign',
'Donor',
'Media',
'Admin',
'Common',
'CommonModules',
'Event',
'Cards',
'Mail'
]
這個我的項目文件夾結構基於django。 任何幫助將非常感激。 謝謝
<pre>
[projectname]/
├── [admin]/
├── campaign/
├── card/
├── common/
├── commonmodules/
├── donor/
├── event/
├── gavagives/
│ ├── __init__.py
│ ├── cel.py
│ ├── cronjobs.py
│ ├── custom_commands.py
│ ├── settings.py
│ ├── urls.py
│ ├── views.py
│ ├── wsgi.py
├── logs/
├── Mail/
│ ├── mail.py
│ ├── views.py
├── node_modules/
├── manage.py
├── README.rst
├── requirements.txt
├── .env
├── Users/
│ ├── __init__.py
│ ├── admin.py
│ ├── apps.py
│ ├── cronjobs.py
│ ├── models.py
│ ├── urls.py
│ ├── validations.py
│ ├── views.py
├── venv/
│ ├── include
│ ├── Lib
│ ├── Scripts
│ ├── tcl
├── License.txt
├── .gitignore
</pre>
按照django documentation
,應用程序必須包含models
被視為一個Django應用程序。 基本上你在這里創建一個package
,所以你不需要將它包含在INSTALLED_APPS
。 要允許項目中的其他應用程序/程序包/模塊使用Mail
文件夾中的文件,您需要在該文件夾中創建__init__.py
文件。 如果文件夾中沒有__init__.py
文件,Python將不再在該目錄中查找子模塊,因此導入模塊的嘗試將失敗。 有關如何從常規包導入的更多信息可以在python documentation
找到。
你需要使用pip導入郵件python發送網格。
你在juper筆記本或命令中輸入這一行。
pip install mail python sendgrid
要么
pip3 install mail python sendgrid
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.