应用程序在启动时返回404

时间:2013-10-10 19:30:28

标签: python flask

我创建了一个Flask应用程序,其结构如下:

/nhs-listpull
/listpull
    /static
    /templates
    __init__.py
    models.py
    views.py
app.db
config.py
run.py

run.py

from listpull import app
app.run(debug=True)

/ listpull / __初始化__。PY

from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
from mom.client import SQLClient
from smartfocus.restclient import RESTClient

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

db = SQLAlchemy(app)
...

/listpull/views.py

import logging
import time
from flask import request, render_template, flash, redirect, send_file
from zlib import compress, decompress
from StringIO import StringIO


@app.route('/')
def index():
    ... do stuff ...
    return render_template('jobs.html', jobs=jobs)

当我运行./run.py时,Web服务器启动,但浏览返回404。

知道为什么吗?

1 个答案:

答案 0 :(得分:0)

永远不会导入

listpull/views.py,因此不会注册任何路由。您需要在__init__.py文件中导入它(小心循环导入):

...

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

db = SQLAlchemy(app)

...

import listpull.views