请求的网址未找到。在pythonanywhere中出现了404错误。

huangapple go评论68阅读模式
英文:

The Requested url not found. 404 error in pythonanywhere

问题

我有一个Flask应用程序,我想在pythonanywhere.com上运行。我已经按照链接1链接2的说明操作,但无法解决问题。我的Flask应用程序名称是 tourismmining,目录内容如下:

应用程序结构

我的应用程序结构如下:

tourismmining
|-> instance
|-> mining
|-> resources
|-> entry.py
|-> installation.txt
|-> License
|-> Procfile
|-> README.rst
|-> requirements.txt

核心应用程序位于 mining 目录中,结构如下:

mining
|-> config
|-> db
|-> exceptions
|-> files
|-> forms
|-> logs
|-> models
|-> sink
|-> static
|-> templates
|-> __init__.py
|-> main.py
|-> utils.py

因此,仅通过Flask本地服务器,我过去运行以下命令

 cd tourismmining

 python -m mining.main  

以下是输出

请求的网址未找到。在pythonanywhere中出现了404错误。

在touristmining中,我编写了另一个名为 entry.py 的文件,它包含


      from mining import app

      if __name__ == '__main__':
          app.run(debug=True)

然后我使用以下命令运行文件 entry.py

   cd tourismmining

   python entry.py 

请求的网址未找到。在pythonanywhere中出现了404错误。

现在,在将相同的代码上传到pythonanywhere之后,目录结构如下

请求的网址未找到。在pythonanywhere中出现了404错误。

设置虚拟环境并尝试了两种配置wsgi文件的方法,如下所示

import sys
path = '/home/s1782662edin/tourismmining'
if path not in sys.path:
   sys.path.insert(0, path)

from mining import app as application
import sys
path = '/home/s1782662edin/tourismmining'
if path not in sys.path:
   sys.path.insert(0, path)

from entry import app as application

然后重新加载网站,但仍然不起作用。显示以下信息

Not Found
The requested URL was not found on the server. If you entered the URL manually please check your 
spelling and try again.
英文:

I have Flask app, and I wanted to run in pythonanywhere.com. I have followed the links Link1, Link2, couldn't resolve the issue. My flask app name is tourismmining and the contents of the directory is listed under

Application Structure

My application is structured in the below way.

tourismmining
|-> instance
|-> mining
|-> resources
|-> entry.py
|-> installation.txt
|-> License
|-> Procfile
|-> README.rst
|-> requirements.txt

The core application is in the directory mining and is structured in the following way

mining
|-> config
|-> db
|-> exceptions
|-> files
|-> forms
|-> logs
|-> models
|-> sink
|-> static
|-> templates
|-> __init__.py
|-> main.py
|-> utils.py

So, just by flask local server, I used to run the below command

 cd tourismmining

 python -m mining.main  

and below is the output

请求的网址未找到。在pythonanywhere中出现了404错误。

In touristmining, I have written an another file named entry.py, and it contains


      from mining import app

      if __name__ == '__main__':
          app.run(debug=True)

And I run the file entry.py using the below command

   cd tourismmining

   python entry.py 

请求的网址未找到。在pythonanywhere中出现了404错误。

Now, after uploading the same code in to pythonanywhere, the directory structure is given below

请求的网址未找到。在pythonanywhere中出现了404错误。

Setting up the virtual environment and tried two ways of configuring the wsgi file which are given below

import sys
path = '/home/s1782662edin/tourismmining'
if path not in sys.path:
   sys.path.insert(0, path)

from mining import app as application
import sys
path = '/home/s1782662edin/tourismmining'
if path not in sys.path:
   sys.path.insert(0, path)

from entry import app as application

And reload the website, nothing worked out. Its says

Not Found
The requested URL was not found on the server. If you entered the URL manually please check your 
spelling and try again.

答案1

得分: 1

确保已定义路由,并且在从矿业导入应用程序时运行定义路由的代码。

英文:

Make sure that you have routes defined and that the code for defining the routes is run when app is imported from mining.

huangapple
  • 本文由 发表于 2020年1月4日 12:34:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/59587907.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定