render_template() takes exactly 1 argument
来源:互联网 发布:stl源码剖析第二章 编辑:程序博客网 时间:2024/06/06 05:21
python新手,刚开始用Pycharm。
今天遇到一个很蠢的问题。。以为是python版本不兼容发现是我想多了。。浪费了时间,希望给其他遇到这种智障问题的朋友提供一个提醒。。
错误是这样的:
TypeErrorTypeError: render_template() takes exactly 1 argument (2 given)Traceback (most recent call last)File "/Library/Python/2.7/site-packages/flask/app.py", line 1994, in __call__return self.wsgi_app(environ, start_response)File "/Library/Python/2.7/site-packages/flask/app.py", line 1985, in wsgi_appresponse = self.handle_exception(e)File "/Library/Python/2.7/site-packages/flask/app.py", line 1540, in handle_exceptionreraise(exc_type, exc_value, tb)File "/Library/Python/2.7/site-packages/flask/app.py", line 1982, in wsgi_appresponse = self.full_dispatch_request()File "/Library/Python/2.7/site-packages/flask/app.py", line 1614, in full_dispatch_requestrv = self.handle_user_exception(e)File "/Library/Python/2.7/site-packages/flask/app.py", line 1517, in handle_user_exceptionreraise(exc_type, exc_value, tb)File "/Library/Python/2.7/site-packages/flask/app.py", line 1612, in full_dispatch_requestrv = self.dispatch_request()File "/Library/Python/2.7/site-packages/flask/app.py", line 1598, in dispatch_requestreturn self.view_functions[rule.endpoint](**req.view_args)File "/Users/sherry/PycharmProjects/c2/c2.py", line 16, in profilereturn render_template("profile.html", uid )TypeError: render_template() takes exactly 1 argument (2 given)
一直以为是包的问题,结果并不是!
划重点。。。
TypeError: render_template() takes exactly 1 argument (2 given)
问题&解决方案:
render_template真的只接受一个位置参数(模板名称),但是其余的参数(在* *上下文)作为关键字参数提供。否则模板中没有办法参考你传入的变量(你必须给他们明确的名称),例如:
return render_template('index.html', f1=f1, f2=f2)
我错在f1, f2没赋值。写代码debug经验不足,浪费了一些时间,写个博客惩罚一下自己的粗心,也希望对遇到这个问题的新手有帮助。
0 0
- render_template() takes exactly 1 argument
- PAMIE TypeError: getElementsByTagName() takes exactly 1 positional argument (2 given)
- Python 'takes exactly 1 argument (2 given)' Python error
- TypeError: checkcode() takes exactly 1 argument (2 given)
- Python 'takes exactly 1 argument (2 given)' Python error
- Python: TypeError: XXX() takes exactly 1 argument (2 given)
- PamIE 和COM调用IE出错: TypeError: getElementById() takes exactly 1 argument (2 given)
- django中报错TypeError: su() takes exactly 1 argument (2 given)的解决办法
- 在调用外部.py文件class内的函数出现takes exactly 1 argument (2 given)解决方案
- How to fix the python problem 'xxx() takes exactly one argument'
- TypeError: __init__() takes exactly 2 arguments (1 given)(已解决)
- Compiler error: must take exactly one argument
- python 调用super()初始化报错“TypeError: super() takes at least 1 argument”
- python 调用super()初始化报错“TypeError: super() takes at least 1 argument”
- #Tensorflow# TypeError: set_shape() takes 1 positional argument but 2 were given
- TypeError: print_space() takes exactly 2 arguments (3 given)
- TypeError: distinct() takes exactly 2 arguments (3 given)
- TypeError: __init__() takes exactly 2 arguments (3 given)
- Codeforces 653C Bear and Up-Down【暴力+思维】题目还不错~
- poj 1837 Balance 二维背包
- 关系代数中的除法运算(转载)
- 详解EditText输入监听TextWatcher
- 打印日期
- render_template() takes exactly 1 argument
- 垃圾归垃圾,渣滓归渣滓。尘土归尘土
- 欢迎使用CSDN-markdown编辑器
- 画图游戏(博弈论)
- 树莓派开发系列教程3——树莓派rasp-config配置
- 专治windows非MBR引导无法激活
- 老鼠走迷宫
- 机器学习算法概述
- 二叉树入门个人总结