404错误在服务器上找不到请求的URL

时间:2014-12-31 12:09:51

标签: python flask migration flask-sqlalchemy flask-login

我有一个基于miguelgrinberg教程的应用程序,它包含:

flask
 run.py
 config.py
 db_migrate.py
 db_craete.py
 db_repository
 app
     __init__.py
     viw.py
     model.py
     form.py
     tmp
     static

我对模型进行了一些更改,然后使用./db_migrate.py来更新数据库但是我收到了这个错误

Traceback (most recent call last):
  File "run.py", line 2, in <module>
    from app import app
  File "/home/peg/flask/app/ __ init __.py", line 13, in <module>
    from app import view, model

所以我从应用程序导入视图中删除了(__ init __.py)中的模型行并运行db_migrate.py但是当我运行应用程序时出现404错误,所以问题出在哪里,我该如何解决?

  

__ init __。py

#!flask/bin/python
from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.login import LoginManager

app = Flask(__name__)
app.config.from_object('config')
db = SQLAlchemy(app)
lm = LoginManager()
lm.init_app(app)
lm.login_view = 'login'

from app import view, model # should delete this line to solve error Traceback 
  

db_migrate.py

  #!flask/bin/python
    import imp
    from migrate.versioning import api
    from app import db # Error here for traceback
    from config import SQLALCHEMY_DATABASE_URI
   .... other stuff....

...

  

view.py

@lm.user_loader
def load_user(id):
    return User.query.get(int(id))


@app.before_request
def before_request():
    g.user = current_user


@app.route('/')
@app.route('/index')
@login_required
def index():
    user = g.user
    return render_template('index.html',
            user = user,
            title ='Home')

1 个答案:

答案 0 :(得分:0)

尝试将目录从“tmp”更改为Flask默认的“模板”。

如果必须,您可以像这样覆盖Flask的默认模板目录名。

在__init__.py文件中

app = Flask(__name__, template_folder='tmp')

source | Flask API .10 - Application Object