英文:
How do I get Pythonanywhere's web app to work with my new files?
问题
抱歉,似乎存在一些问题。可能是因为服务器期望读取的确切文件已被删除,替换也不正确,因此感到困惑。
我尝试重新加载应用程序、更改应用程序的源代码目录、工作目录和 WSGI 配置文件,指向包含我的新 backend.py 文件的目录。我尝试将文件内容放回原来的 "mysite" 文件夹中,但似乎无法使 Web 应用程序像那个 "hello world" 文件一样工作。
我可能遗漏了一些简单的内容。也许我需要在 URL 连接到的 Python 文件中指定文件名?如果是这样,我应该在哪里指定?我的 Python 文件中是否遗漏了一些基本内容?
以下是一些可能有用的信息。错误日志显示某个文件找不到模块,但我不知道是哪个文件引发了此错误,如何修复,或者是我做了什么引起了这个问题。
感谢您的帮助。
英文:
I am using Pythonanywhere to host a simple Flask web app for an academic project. The tutorial set me up with a simple flask_app.py hello world file that showed up at the url provided.
I then deleted that example file and used the bash console to import files from my project group's github repo, expecting the app to now work off of my own files rather than the hello world file. However, whenever I try to run it, I get a "Something went wrong" error
Apologies if a similar question has been answered before, I was unable to find it in a cursory search.
I assume that the issue here is that the server is expecting to read the exact hello world file that I deleted, and is confused because I replaced it incorrectly.
I have tried reloading the app using the reload button, changing the app's source code directory, working directory, and WSGI config file to point at the directory containing my new backend.py file, I have tried putting the contents of my files back into the original "mysite" folder. Still, I cannot seem to get the web app to work as it did with that hello world file.
I know I must be missing something stupid. Do I perhaps need to specify the name of the python file I want the url to be connected to? If so, where? Am I missing something basic in my python file?
Below is some info that may be helpful. The Error log shows that some file cant find a module, however I have no idea what file is throwing this error, how to fix it, or what I did to cause this.
Thanks for your help.
Screenshot of config file locations, I have reset them to the default.
The contents of that "mysite" folder that the hello world was originally in.
Error Log for the day of troubleshooting:
2023-02-10 16:40:46,043: If you're seeing an import error and don't know why,
2023-02-10 16:40:46,043: we have a dedicated help page to help you debug:
2023-02-10 16:40:46,044: https://help.pythonanywhere.com/pages/DebuggingImportError/
2023-02-10 16:40:46,044: ***************************************************
2023-02-10 16:40:48,418: Error running WSGI application
2023-02-10 16:40:48,418: ModuleNotFoundError: No module named 'flask_app'
2023-02-10 16:40:48,418: File "/var/www/stagesetupapp_pythonanywhere_com_wsgi.py", line 16, in <module>
2023-02-10 16:40:48,418: from flask_app import app as application # noqa
2023-02-10 16:40:48,419: ***************************************************
2023-02-10 16:40:48,419: If you're seeing an import error and don't know why,
2023-02-10 16:40:48,419: we have a dedicated help page to help you debug:
2023-02-10 16:40:48,419: https://help.pythonanywhere.com/pages/DebuggingImportError/
2023-02-10 16:40:48,419: ***************************************************
2023-02-13 16:14:17,492: Error running WSGI application
2023-02-13 16:14:17,495: ModuleNotFoundError: No module named 'flask_app'
2023-02-13 16:14:17,495: File "/var/www/stagesetupapp_pythonanywhere_com_wsgi.py", line 16, in <module>
2023-02-13 16:14:17,496: from flask_app import app as application # noqa
2023-02-13 16:14:17,496: ***************************************************
2023-02-13 16:14:17,496: If you're seeing an import error and don't know why,
2023-02-13 16:14:17,496: we have a dedicated help page to help you debug:
2023-02-13 16:14:17,496: https://help.pythonanywhere.com/pages/DebuggingImportError/
2023-02-13 16:14:17,496: ***************************************************
答案1
得分: 1
当你在PythonAnywhere上部署一个Web应用时,它会自动创建一个wsgi文件(因为目前在PA上的Web应用必须兼容WSGI)。这个文件可以通过你的Web应用的网页访问到。你需要更新该文件,提供正确的路径指向你的项目和application
对象(我猜在你的情况下应该是from backend import app as application
,假设该路径是可用的)。关于调试提示,你可以随时回到错误日志中链接的页面(你之前复制的链接):https://help.pythonanywhere.com/pages/DebuggingImportError/。
英文:
When you deploy a web app on PythonAnywhere it automatically creates a wsgi file (as currently web apps on PA have to be WSGI compatible) -- this file is accessible via the Web page of your web app. You have to update the file providing correct paths to your project and the application
object (I guess in your case that would be from backend import app as application
, assuming that path is available). For debugging tips you can always fall back to the page that is linked in the error log (which you copied above): https://help.pythonanywhere.com/pages/DebuggingImportError/.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论