Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/358.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Flask应用程序仅返回404';不管它是如何运行的_Python_Nginx_Flask_Uwsgi - Fatal编程技术网

Python Flask应用程序仅返回404';不管它是如何运行的

Python Flask应用程序仅返回404';不管它是如何运行的,python,nginx,flask,uwsgi,Python,Nginx,Flask,Uwsgi,我似乎无法在uWSGI上正确运行我的应用程序。通过从命令行运行uWSGI,我将nginx从等式中去掉,它表现出与在nginx上运行时完全相同的行为 uwsgi -s 0.0.0.0:5050 -w app:app --uid www-data --gid www-data --protocol=http uwsgi按如下方式处理请求: [pid:0625|app: 0|req: 1/1] 192.168.1.219 () {34 vars in 737 bytes} [Tue Mar 31 1

我似乎无法在uWSGI上正确运行我的应用程序。通过从命令行运行uWSGI,我将nginx从等式中去掉,它表现出与在nginx上运行时完全相同的行为

uwsgi -s 0.0.0.0:5050 -w app:app --uid www-data --gid www-data --protocol=http
uwsgi按如下方式处理请求:

[pid:0625|app: 0|req: 1/1] 192.168.1.219 () {34 vars in 737 bytes} [Tue Mar 31 11:10:30 2015] GET /admin => generated 233 bytes in 25 msecs (HTTP/1.1 404) 3 headers in 249 bytes (1 switches on core 0)
我的文件结构如下

/srv/www/cc/app/
               static/
               templates/
               __init__.py
               views.py
               models.py
               forms.py
鉴于有新证据表明它可能是我的应用程序,以下是我的init.py文件:

import os
from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.script import Manager
from flask.ext.migrate import Migrate, MigrateCommand

app = Flask(__name__)
app.config.from_object('config')

db = SQLAlchemy(app)
migrate = Migrate(app, db)

manager = Manager(app)
manager.add_command('db', MigrateCommand)

from flask.ext.mail import Mail
mail = Mail(app)

from app import models, forms

#setup flask-security
from flask.ext.security import Security, SQLAlchemyUserDatastore

user_datastore = SQLAlchemyUserDatastore(db, models.User, models.Role)
security = Security(app, user_datastore,
    confirm_register_form = forms.ExtendedConfirmRegisterForm
    )

from app import views
链接到my Complete views.py:

在开发的早期,我就有过同样的应用程序,运行在不同的nginx+uwsgi服务器上,并且完全复制了它们的配置文件,但没有效果。我真的不明白为什么这行不通。但根据烧瓶文档,以上是我所需要的全部

对于傻笑,我继续,并从方程中删除了uwsgi。已在cc文件夹中创建run.py文件。。。python run.py:

from app import app
app.run('0.0.0.0', port=5050, debug=True)
以及请求:

* Running on http://0.0.0.0:5050/
* Restarting with reloader
192.168.1.219 - - [31/Mar/2015 11:56:24] "GET / HTTP/1.1" 404 -
所以这似乎是我的应用程序的一个问题,而不是关于nginx或uwsgi的任何问题。但是我没有任何错误。。。会出什么问题

编辑

通过评论中的建议做了更多的挖掘。我已编辑了我的init.py的底部:

import . import views

print views
print app.url_map
这是我启动服务器时的输出:

* Running on http://0.0.0.0:5050/
* Restarting with reloader
<module 'app.views' from '/srv/www/cc/app/views.py'>
Map([<Rule '/' (HEAD, POST, OPTIONS, GET) -> index>,
<Rule '/admin/' (HEAD, POST, OPTIONS, GET) -> admin>,
<Rule '/test/' (HEAD, POST, OPTIONS, GET) -> test>
...
Lots more ... ])
*在上运行http://0.0.0.0:5050/
*使用重新加载程序重新启动
地图([索引>,,
管理员>,
测试>
...
更多…)

如果设置
服务器\u NAME
配置值,则必须与应用程序外部服务的主机和端口匹配。请将其注释掉,或者使其与服务器的域或ip匹配

app.config['SERVER_NAME'] = 'example.com:80'

运行dev服务器时,名称将为
localhost:5000
,尽管在这种情况下通常不需要设置它。

看起来您从未加载视图/路由/蓝图。我想知道是否将
从应用程序导入视图更改为
从。导入视图
works(?)@adarsh我同意。不过,我在文件中添加了一些打印语句,它似乎正确地输入了我的view.py文件。如果我在导入过程中没有收到任何错误,我是否可以不假定所有操作都已按计划进行?您是否可以检查
\uu init\uuuuuuuuuuupy
中的
app.url\u map
?(当然在导入视图后)@adarsh更新了您的建议。奇怪的是,这些路线似乎已注册到应用程序中。你能给我看一下你的视图文件吗?(部分或全部)