问题:

  路由完全正确,当只有一个名为home的函数处理这个路由时候,下一个路由处理函数,总是提示没有这个rotue属性

Traceback (most recent call last):
File "E:/workspace/wei-move/manage.py", line 3, in <module>
from app import app
File "E:\workspace\wei-move\app\__init__.py", line 10, in <module>
from app.home import home as home_blueprint
File "E:\workspace\wei-move\app\home\__init__.py", line 7, in <module>
import app.home.views
File "E:\workspace\wei-move\app\home\views.py", line 16, in <module>
@home.route('/login/')
AttributeError: 'function' object has no attribute 'route'

问题原因:

  本质是home函数名和@home装饰器有冲突,当取和装饰器或者对应的app一样的名字时候,只能对应一个home函数生效,后面的路由函数都将报错处理

# coding:utf8

from flask import render_template as render, redirect, url_for
# render_template 返回模板
# redirect 路由重定向
# url_for 联合路由重定向,指向对应app的url地址
from . import home # 首页
@home.route('/')
def home():
return render('home/index.html') # 登录页面
@home.route('/login/')
def login():
return render('home/login.html')

那,如何解决这个问题?

  由于函数名和路由装饰器名相同引起的错误,当把函数名和装饰路由相同的名字替换成其他名字,一定要娶和路由装饰器一样的名字需要在前面加个下划线,进行区分

# 首页
@home.route('/')
def _home():
return render('home/index.html') # 登录页面
@home.route('/login/')
def login():
return render('home/login.html')

flask_route错误:AttributeError: 'function' object has no attribute 'route'的更多相关文章

  1. tensorboardX使用中 AttributeError: 'function' object has no attribute 'graph'

    最近在使用tensorboardX可视化网络结构,因为tensorboardX并非pytorch原生的可视化工具,所以版本之间并不兼容 在使用的过程中会遇到,AttributeError: 'func ...

  2. python 错误AttributeError: 'module' object has no attribute 'AF_INET'

    写了一个简单的python socket的程序.运行时,报错如下 原因:文件的命名与Python的function的命名冲突 修改名称后,发现还是无法运行,检查目录下面是否有 这样子的一个文件,删除即 ...

  3. AttributeError: 'function' object has no attribute 'as_view'

    我的描述:当我启用jwt_required来进行token验证的时候,我提示错误; 解决方案: 修改前代码: 修改后代码: 多看书.多多了解.多看看世界...

  4. python调用对象属性出错:AttributeError: 'function' object has no attribute '_name_'

    出错如下图所示: 原来是因为把__name__写成_name_, 下图为正确结果:

  5. python3错误AttributeError: 'TestSequenceFunctions' object has no attribute 'seq'

    对比了两段代码发现,原来是setUp要用用大写才能被正确引用. 修改后,代码运行成功.

  6. AttributeError: 'WebElement' object has no attribute 'send_keys'

    这个是没问题的代码:用来打开谷歌搜索cheese并退出 from selenium import webdriver from selenium.common.exceptions import Ti ...

  7. pycharm install python packaging tools时遇到AttributeError: '_NamespacePath' object has no attribute 'sort'错误

    pycharm install python packaging tools时报错AttributeError: '_NamespacePath' object has no attribute 's ...

  8. Python错误:AttributeError: 'generator' object has no attribute 'next'解决办法

    今天在学习生成器对象(generation object)运行以下代码时,遇到了一个错误: #定义生成器函数def liebiao(): for x in range(10): yield x#函数调 ...

  9. django错误笔记(xadmin)——AttributeError: 'Settings' object has no attribute 'TEMPLATE_CONTEXT_PROCESSORS'

    使用Xadmin,执行makemigrations和migrate时运行报错提示: AttributeError: 'Settings' object has no attribute 'TEMPLA ...

随机推荐

  1. JDK1.8中的线程池

    上面这段代码一直在用,面试的时候也经常被问到,却从未深究过,不知道线程池到底是怎么回事,今天看看源代码,一探其究竟 线程池主要控制的状态是ctl,它是一个原子的整数,其包含两个概念字段: worker ...

  2. KMP算法讲解

    老规矩,讲算法前,先说一道小问题吧 给你一个长串和短串,求短串在长串中出现的次数和位置. 设长串长度为len1,短串长度为len2. 如果len1*len2<=108,那就很简单了,直接暴力枚举 ...

  3. sso示例代码

    个人写的一个关于在ASP.NET 中如何实现SSO单点登录,这可能也是.NET实现大型互联网项目的第一步要解决的问题.已经放到GitHub上供大家参考.https://github.com/bidia ...

  4. swiper插件的简单使用,实现图片轮播

    移动端和p c端经常会遇到写轮播图的情况,这里只是简单的说一下swiper插件的简单用法(移动端为例). <!DOCTYPE html> <html lang="en&qu ...

  5. [].slice.call(arguments,1)

    [转] 前言 今天偶然翻资料看到一个叫做软绑定的函数,用来确定this的; 原代码 if(!Function.prototype.softBind){ Function.prototype.softB ...

  6. js中时间的处理

    转自 : http://blog.csdn.net/xichenguan/article/details/45512541 //将格林时间转换成字符串格式的,用于显示带页面 time : 格林时间 v ...

  7. AWS上获取监控数据(EC2/RDS都支持)

    方法1:mon-cmd http://docs.aws.amazon.com/zh_cn/AmazonCloudWatch/latest/cli/SetupCLI.html(安装连接) ● Step ...

  8. JavaScript基础知识(概念、常量和变量)

    1.JavaScript概念 JavaScript是脚本语言; 编写之后,可以直接运行(缺失了编译的过程) 2.JavaScript发展 LiveScript    =>    JavaScri ...

  9. Two Sum(两个数的相加)

    2017.11.10题目描述:Given nums = [2, 7, 11, 15], target = 9, Because nums[0] + nums[1] = 2 + 7 = 9, retur ...

  10. Redis进阶实践之三如何在Windows系统上安装安装Redis

    一.Redis的简介        Redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合 ...