BuildError: Could not build url for endpoint 'show'. Did you mean 'api.show' instead?
2018-03-14 11:39
661 查看
在使用蓝图重定向时报错
我觉得原因大概是第一次使用蓝图时已经为这个视图添加了一次路由映射,
而我重定向时直接重定向到这个函数,会再次在程序实例的url_map中添加这个视图的路由映射,但是之前已经添加过一次了,所以会报这个错,他提醒我让我重定向时使用api这个蓝图下的路由映射api.show
BuildError: Could not build url for endpoint 'show'. Did you mean 'api.show' instead?
我觉得原因大概是第一次使用蓝图时已经为这个视图添加了一次路由映射,
而我重定向时直接重定向到这个函数,会再次在程序实例的url_map中添加这个视图的路由映射,但是之前已经添加过一次了,所以会报这个错,他提醒我让我重定向时使用api这个蓝图下的路由映射api.show
from flask import Blueprint,render_template,request,redirect,url_for,flash # 创建蓝图对象 api = Blueprint('api',__name__) from app import Authors,Books,db,InfoForm # 使用蓝图对象添加路由映射到列表 @api.route('/add') def add(): au_xi = Authors(name='我吃西红柿') au_qian = Authors(name='萧潜') au_san = Authors(name='唐家三少') bk_xi = Books(name='吞噬星空',au=1) bk_xi2 = Books(name='寸芒',au=2) bk_qian = Books(name='飘渺之旅',au=1) bk_san = Books(name='冰火魔厨',au=3) # 把数据提交给用户会话 db.session.add_all([au_xi, au_qian, au_san, bk_xi, bk_xi2, bk_qian, bk_san]) # 提交会话 db.session.commit() return '添加成功' @api.route('/show',methods=['GET','POST']) def show(): """展示数据,获取用户输入的数据""" # 查询所有作者 db.session.rollback() authors = Authors.query.all() # 查询所有书籍 books = Books.query.all() # 创建表单对象传入到模板中 form = InfoForm() if request.method == 'POST': if form.validate_on_submit(): author = form.author.data book = form.book.data # 保存信息 au = Authors(name=author) bk = Books(name=book,au=au.id) # 把信息交给数据库会话 db.session.add_all([au,bk]) db.session.commit() else: flash('提交信息错误') 重定向时要带上蓝图的名字.函数名 return redirect(url_for('api.show')) # 渲染模板 return render_template('shows.html',authors=authors,books=books,form=form)
相关文章推荐
- BuildError: Could not build url for endpoint 'main.index'. Did you mean 'main.indexs' instead?
- BuildError: Could not build url for endpoint 'auth.register'(关键词:Web开发/Flask/bug)
- Could not resolve URL for hyperlinked relationship using view name "xxx:api:xxx-detail". Y
- 'NSURL' is not implicitly convertible to 'URL'; did you mean to use 'as' to explicitly convert?异常
- 访问Storm ui界面,出现org.apache.storm.utils.NimbusLeaderNotFoundException: Could not find leader nimbus from seed hosts ["master" "slave1"]. Did you specify a valid list of nimbus hosts for confi的问题解决(图文详解)
- 访问Storm ui界面,出现org.apache.storm.utils.NimbusLeaderNotFoundException: Could not find leader nimbus from seed hosts ["master"]. Did you specify a valid list of nimbus hosts for confi的问题解决(图文详解)
- ERROR (DiscoveryFailure): Could not determine a suitable URL for the plugin
- 1.storm问题总结 Could not find leader nimbus from seed hosts [localhost] Did you specify a valid list of
- 1.storm问题总结 Could not find leader nimbus from seed hosts [localhost] Did you specify a valid list of
- intellij中编译报错: The packaging for this project did not assign a file to the build artifact
- "The target '__Page' for the callback could not be found or did not implement ICallbackEventHandler."的解决办法
- 1.storm问题总结 Could not find leader nimbus from seed hosts [localhost] Did you specify a valid list of
- 1.storm问题总结 Could not find leader nimbus from seed hosts [localhost] Did you specify a valid list of
- Could not find property 'outputFile' on com.android.build.gradle.internal.api.ApplicationVariantImpl
- The tag handler class for "c:set"(org.apache.taglibs.standard.tag.rt.core.UrlTag)was not found on the Java Build Path
- Could not resolve dependencies for project com.koolearn:koo-b2b-tesa-api:jar:1.0-dev-SNAPSHOT
- Could not resolve URL for hyperlinked relationship using view name
- flink出现could not find implicit value for evidence parameter of type org.apache.flink.api.com
- Could not read from System Tables. You must grant SELECT access on all system tables for the databas
- 1.storm问题总结 Could not find leader nimbus from seed hosts [localhost] Did you specify a valid list of