简体   繁体   English

PythonAnywhere.com Flask Web应用程序:没有名为“ flask_app”的模块

[英]PythonAnywhere.com Flask web app: no module named 'flask_app'

I am new to Python Anywhere and I'm trying to set up a Flask web app I have already built. 我是Python Anywhere的新手,我正在尝试建立一个已经构建的Flask Web应用程序。 I followed this tutorial: https://help.pythonanywhere.com/pages/Flask/ 我遵循了本教程: https : //help.pythonanywhere.com/pages/Flask/

But when I try to access the site the log says this: 但是,当我尝试访问该站点时,日志显示以下内容:

Error running WSGI application
2018-07-24 11:25:47,696: ModuleNotFoundError: No module named 'flask_app'
2018-07-24 11:25:47,697:   File "/var/www/vdvaxel_pythonanywhere_com_wsgi.py", line 111, in <module>
2018-07-24 11:25:47,697:     from flask_app import app as application  # noqa

I followed the tutorial step by step but still it doesn't work. 我一步一步地遵循了本教程,但是仍然行不通。 Can someone explain me what is wrong? 有人可以解释我哪里错了吗?

You need to replace flask_app with the name of the file containing app and the app structure (routes, etc). 您需要用包含app和应用程序结构(路由等)的文件名替换flask_app Navigate to: 导航:

https://www.pythonanywhere.com/user/{your_username}/files/var/www/vdvaxel_pythonanywhere_com_wsgi.py

Then, on the last line of the file, which is currently from flask_app import app as application , replace flask_app with the filename of your current app: 然后,在文件的最后一行(当前from flask_app import app as application ,将flask_app替换为当前应用程序的文件名:

from my_new_web_app import app as application

Also, ensure that project_home in the wsgi file is pointing to the folder that stores your flask app file, along with any other folders such as templates , static , etc. To find the proper path, navigate to the folder itself and copy the "breadcrumb" navigation, just below the pythonanywhere logo. 另外,请确保wsgi文件中的project_home指向存储flask应用程序文件的文件夹,以及所有其他文件夹(例如templatesstatic等)。要找到正确的路径,请导航至该文件夹本身并复制“ breadcrumb”导航,位于pythonanywhere徽标下方。

Then save the file and access your site again. 然后保存文件并再次访问您的站点。

It's difficult to answer without the details of your code structure. 没有代码结构的细节,很难回答。

1) Is your Flask web app in a file called flask_app.py ? 1)Flask Web应用程序是否在名为flask_app.py的文件中?

2) Have you uncommented and updated the block of code from section Configuring the WSGI file : 2)您是否已取消注释和更新了“ 配置WSGI文件”部分中的代码块:

import sys
path = '/home/yourusername/mysite'
if path not in sys.path:
    sys.path.append(path)

so the path variable value really is the path were the flask_app.py file is located ? 所以path变量值的确是flask_app.py文件所在的路径吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM