我正试图将我的flask代码转换成python包结构,但是现在我已经完成了,当我尝试运行代码时,没有找到任何HTML模板。
这是我目前的烧瓶包装的简化结构。
run.py
是用来执行烧瓶代码的。
routes.py
包含我所有
@app.routes
调用HTML模板的位置。
pipeline-ui/
run.py
pipeline_app/
__init__.py
routes.py
models.py
forms.py
templates/
pipeline-alt.html
我得到的错误消息是:
TemplateNotFound: pipeline-alt.html
P.I.
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_bcrypt import Bcrypt
from flask_login import LoginManager
app = Flask('__name__')
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///site.db'
db = SQLAlchemy(app)
bcrypt = Bcrypt(app)
login_manager = LoginManager(app)
login_manager.login_view = 'login'
login_manager.login_message_category = 'info'
from pipeline_app import routes
奔驰:
from pipeline_app import app
if __name__ == '__main__':
app.run(debug=True)
PY:
from flask import url_for, render_template, request, flash, redirect
from pipeline_app import app
from pipeline_app.forms import InputForm, RegistrationForm, LoginForm
from pipeline_app.models import User, Post
from flask_login import login_user, current_user, logout_user, login_required
from math import ceil
import json
import subprocess
import os
import sys
from pprint import pprint
@app.route('/', methods=['GET', 'POST'])
def pipeline():
form = InputForm(request.form)
if request.method == 'POST':
if form.validate_on_submit():
STACK_NAME = request.form['stack_name']
# Store data in database for future use
db.create_all()
db_inputs = Post(stack_name=STACK_NAME)
db.session.add(db_inputs)
db.session.commit()
return render_template('pipeline-alt.html',
title='Pipeline Input',
form=form,
STACK_NAME=STACK_NAME)