關於這個問題有很多問題,但我花了7個小時試着寫在這裏的所有東西,而且我仍然在Flask中嘗試呈現最基本的404錯誤index.html的。Flask中的404錯誤
編輯:我剝我的代碼下來,我仍然得到一個404碼反映最新版本...
我的代碼:
初始化的.py
import os
from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
from config import basedir
app = Flask(__name__)
app.config.from_object('config')
db = SQLAlchemy(app)
from app import views, models
模型。 py
from app import db
from sqlalchemy import create_engine
from sqlalchemy import Column, Integer
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker, relationship, scoped_session
engine = create_engine('sqlite:///bikes.db', convert_unicode=True)
session = scoped_session(sessionmaker(autocommit=False,
autoflush=False,
bind=engine))
Base = declarative_base()
Base.query = session.query_property()
class User(db.Model):
__tablename__="user"
id = db.Column(db.Integer, primary_key = True)
name = db.Column(db.String(15))
email = db.Column(db.String(25))
age= db.Column(db.Integer)
def main():
Base.metadata.create_all(ENGINE)
if __name__ == "__main__":
main()
views.py
from flask import Flask, render_template, session
from app.models import session as db_session
from app import app, db
app = Flask(__name__)
@app.route('/')
def index():
return "Hello, World!"
if __name__ == "__main__":
app.run(debug=True)
你有沒有試過只運行帶有@ app.route('/')的模塊?爲什麼不從小開始並在此基礎上構建? –
@EdgarAroutiounian你輸入的比我快。從小處開始,並在此基礎上進行構建。 – Jivan
謝謝;我已經嘗試過了,現在仍然有404. – fstopzero