我目前正在开发一个应用程序。这个网络应用程序有自己的域。最初创建时,我使用 cname 设置域和注册商,并在几个小时后成功显示“这是一个烧瓶应用程序......”类似的东西。
我决定按照 Grinberg 先生在他的书中的例子(在 localhost 上功能齐全)。所以我将我的个人存储库克隆到 pythonanywhere 并运行以下命令。
python manage.py db init
python manage.py db upgrade
python manage.py migrate
到目前为止,一切都很好。我使用mysql workbench检查了 mysql 数据库。
现在是我的问题。
当我跑步时python manage.py runserver
它向我抛出以下错误。
/home/username/.virtualenvs/webapp/local/lib/python2.7/site-packages
/flask_sqlalchemy/__init__.py:800: UserWarning: SQLALCHEMY_TRACK_MODIFICA
TIONS adds significant overhead and will be disabled by default in the future. Set it to True to suppress this warning.
warnings.warn('SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future. Set it to True to su
ppress this warning.')
Traceback (most recent call last):
File "manage.py", line 20, in <module>
manager.run()
File "/home/username/.virtualenvs/webapp/local/lib/python2.7/site-packages/flask_script/__init__.py", line 412, in run
result = self.handle(sys.argv[0], sys.argv[1:])
File "/home/username/.virtualenvs/webapp/local/lib/python2.7/site-packages/flask_script/__init__.py", line 383, in handle
res = handle(*args, **config)
File "/home/username/.virtualenvs/webapp/local/lib/python2.7/site-packages/flask_script/commands.py", line 425, in __call__
**self.server_options)
File "/home/username/.virtualenvs/webapp/local/lib/python2.7/site-packages/flask/app.py", line 843, in run
run_simple(host, port, self, **options)
File "/home/username/.virtualenvs/webapp/local/lib/python2.7/site-packages/werkzeug/serving.py", line 677, in run_simple
s.bind((hostname, port))
File "/usr/lib/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 98] Address already in use
我尝试禁用 wsgi.py 文件(将所有内容注释掉)仍然相同。
要知道的事情:
- 我有一个付费帐户。
- 这是 pythonanywhere 上的第二个 webapp。(第一个不是根据教程建模的,效果很好)
编辑
我将端口从 5000 更改为 9000。它在控制台中运行。但我不能访问我的网站。我应该注释掉 wsgi 文件吗?
目前它看起来像这样:
import sys
# # add your project directory to the sys.path
project_home = u'/home/username/e_orders/e_orders'
if project_home not in sys.path:
sys.path = [project_home] + sys.path
# # import flask app but need to call it "application" for WSGI to work
from manager import app as application
管理.py
import os
from app import create_app, db
from app.models import User
from flask_script import Manager, Shell, Server
from flask_migrate import Migrate, MigrateCommand
app = create_app(os.getenv('FLASK_CONFIG') or 'default')
manager = Manager(app)
migrate = Migrate(app, db)
def make_shell_context():
return dict(app=app, db=db, User=User)
manager.add_command('shell', Shell(make_context=make_shell_context))
manager.add_command('db', MigrateCommand)
manager.add_command('runserver', Server(port=9000))
if __name__ == '__main__':
manager.run()
编辑 2
上面的 wsgi 配置出现以下错误。
错误日志
ImportError: No module named manager
2016-08-04 17:42:39,589 :Error running WSGI application
Traceback (most recent call last):
File "/bin/user_wsgi_wrapper.py", line 154, in __call__
app_iterator = self.app(environ, start_response)
File "/bin/user_wsgi_wrapper.py", line 170, in import_error_application
raise e
ImportError: No module named manager