I have no problem running my code on my local machine, however, if I try to host it using Python Anywhere I run into issues when trying to use flask_mail module.
I have a lot of files, but I'll try to limit it to what is useful.
This is my routes.py file that I am running on my local machine.
from flask import render_template, url_for, flash, redirect
from crhs_web import app, contactmail
from crhs_web.forms import RegistrationForm
from crhs_web.scripts import gene_expression
from flask_mail import Message
mail = contactmail.mail
mail.init_app(app)
# All routes below here.....
Here is my contactmail.py file located in the same directory as my routes.py
from crhs_web import app
from flask_mail import Mail
mail = Mail()
app.config["MAIL_SERVER"] = "smtp.gmail.com"
app.config["MAIL_PORT"] = 465
app.config["MAIL_USE_SSL"] = True
app.config["MAIL_USERNAME"] = 'email@gmail.com'
app.config["MAIL_PASSWORD"] = 'password'
When running this, I get this error message.
2018-12-11 21:26:19,841: Error running WSGI application
2018-12-11 21:26:19,841: ModuleNotFoundError: No module named 'flask_mail'
2018-12-11 21:26:19,842: File "/var/www/tkellough_pythonanywhere_com_wsgi.py", line 16, in <module>
2018-12-11 21:26:19,842: from run import app as application # noqa
2018-12-11 21:26:19,842:
2018-12-11 21:26:19,842: File "/home/tkellough/mysite/Teaching_Website/run.py", line 1, in <module>
2018-12-11 21:26:19,842: from crhs_web import app
2018-12-11 21:26:19,842:
2018-12-11 21:26:19,842: File "/home/tkellough/mysite/Teaching_Website/crhs_web/__init__.py", line 6, in
<module>
2018-12-11 21:26:19,842: from crhs_web import routes
2018-12-11 21:26:19,842:
2018-12-11 21:26:19,843: File "/home/tkellough/mysite/Teaching_Website/crhs_web/routes.py", line 2, in
<module>
2018-12-11 21:26:19,843: from crhs_web import app, contactmail
2018-12-11 21:26:19,843:
2018-12-11 21:26:19,843: File "/home/tkellough/mysite/Teaching_Website/crhs_web/contactmail.py", line 2, in
<module>
2018-12-11 21:26:19,843: from flask_mail import Mail
2018-12-11 21:26:19,843: ***************************************************
2018-12-11 21:26:19,843: If you're seeing an import error and don't know why,
2018-12-11 21:26:19,843: we have a dedicated help page to help you debug:
2018-12-11 21:26:19,844: https://help.pythonanywhere.com/pages/DebuggingImportError/
However, if I comment out the flask_mail sections (like below) I can run the website without a problem. I just lose the features of my contact form.
from flask import render_template, url_for, flash, redirect
from crhs_web import app#, contactmail
from crhs_web.forms import RegistrationForm
from crhs_web.scripts import gene_expression
# from flask_mail import Message
# mail = contactmail.mail
# mail.init_app(app)
# All routes below here....
I'm really at a loss for what I need to do. My guess is an issue with my virtual environment? But I can't figure out how to ensure I'm doing the right thing. My virtual environment works fine on my local machine. It's location is
/home/tkellough/mysite/Teaching_Website/venv
I've tried editing my virtual environment path to that and I get this error.
Warning: No virtualenv detected at this path. Do you need to create it?
I've tried following the directions on creating a second virtual environment, but still not able to figure it out. If worse comes to worst, I can run the website without using the contact form since everything else works, I just hate not figuring out this last thing.
Any help would be greatly appreciated! I feel very lost and this is the first website I've ever made, but trying to learn everything and organize all my files in the proper locations is a challenging concept for me.