我一直在努力开发应用程序。我想要做的是当edit_todo方法获取todo_id作为参数时,它从数据库获取相关数据。用户编辑文本并单击“提交”按钮后,将转到update_todo方法并更新数据库中的数据。但是,当我处理编辑和更新文本时,我收到此错误。我找不到哪个部分出错了。
这是models.py
@app.route('/edit_todo/<int:todo_id>', methods=['GET'])
@login_required
def edit_todo(todo_id):
if 'todo_id' is not None:
g.todo = query_db('select * from todo where todo_id = ?', [todo_id])
return render_template('edit_todo.html', todo_id=todo_id, todo=query_db('''
select * from todo where todo_id = ?''',[todo_id]))
@app.route('/update_todo/<int:todo_id>', methods=['POST'])
@login_required
def update_todo(todo_id):
if 'user_id' not in session:
abort(401)
if request.form['text']:
g.db.execute('''update todo set text=?, pub_date=? where todo_id=?''', [todo_id],
request.form['text'],
int(time.time()))
g.db.commit()
flash('Your todo was edited')
return redirect(url_for('index'))
这是edit_todo模板
<form action="{{ url_for('update_todo', todo_id=todo.todo.id) }}" method=post>
<dl>
{{ todo.todo_id }}
<dt>Todo:
<dd><input type=text name=text size=60 value="{{ todo.text }}">
</dl>
<div class=actions><input type=submit value="Edit"></div>
</form>
这是用户可以访问edit_todo模板的模板的一部分。
{% for todo in todo %}
<a href="{{ url_for('edit_todo', todo_id=todo.todo_id) }}" class="button">Edit</a>
Edit01:添加了错误消息
TypeError
TypeError: _wrapped_view() takes at least 1 argument (0 given)
Traceback (most recent call last)
File "C:\Python27\lib\site-packages\flask\app.py", line 1994, in __call__
error = None
ctx.auto_pop(error)
def __call__(self, environ, start_response):
"""Shortcut for :attr:`wsgi_app`."""
return self.wsgi_app(environ, start_response)
def __repr__(self):
return '<%s %r>' % (
self.__class__.__name__,
self.name,
File "C:\Python27\lib\site-packages\flask\app.py", line 1985, in wsgi_app
try:
try:
response = self.full_dispatch_request()
except Exception as e:
error = e
response = self.handle_exception(e)
return response(environ, start_response)
finally:
if self.should_ignore_error(error):
error = None
ctx.auto_pop(error)
File "C:\Python27\lib\site-packages\flask\app.py", line 1540, in handle_exception
# if we want to repropagate the exception, we can attempt to
# raise it with the whole traceback in case we can do that
# (the function was actually called from the except part)
# otherwise, we just raise the error again
if exc_value is e:
reraise(exc_type, exc_value, tb)
else:
raise e
self.log_exception((exc_type, exc_value, tb))
if handler is None:
File "C:\Python27\lib\site-packages\flask\app.py", line 1982, in wsgi_app
ctx = self.request_context(environ)
ctx.push()
error = None
try:
try:
response = self.full_dispatch_request()
except Exception as e:
error = e
response = self.handle_exception(e)
return response(environ, start_response)
finally:
File "C:\Python27\lib\site-packages\flask\app.py", line 1614, in full_dispatch_request
request_started.send(self)
rv = self.preprocess_request()
if rv is None:
rv = self.dispatch_request()
except Exception as e:
rv = self.handle_user_exception(e)
return self.finalize_request(rv)
def finalize_request(self, rv, from_error_handler=False):
"""Given the return value from a view function this finalizes
the request by converting it into a response and invoking the
File "C:\Python27\lib\site-packages\flask\app.py", line 1517, in handle_user_exception
return self.handle_http_exception(e)
handler = self._find_error_handler(e)
if handler is None:
reraise(exc_type, exc_value, tb)
return handler(e)
def handle_exception(self, e):
"""Default exception handling that kicks in when an exception
occurs that is not caught. In debug mode the exception will
File "C:\Python27\lib\site-packages\flask\app.py", line 1612, in full_dispatch_request
self.try_trigger_before_first_request_functions()
try:
request_started.send(self)
rv = self.preprocess_request()
if rv is None:
Open an interactive python shell in this frame rv = self.dispatch_request()
except Exception as e:
rv = self.handle_user_exception(e)
return self.finalize_request(rv)
def finalize_request(self, rv, from_error_handler=False):
File "C:\Python27\lib\site-packages\flask\app.py", line 1598, in dispatch_request
# request came with the OPTIONS method, reply automatically
if getattr(rule, 'provide_automatic_options', False) \
and req.method == 'OPTIONS':
return self.make_default_options_response()
# otherwise dispatch to the handler for that endpoint
return self.view_functions[rule.endpoint](**req.view_args)
def full_dispatch_request(self):
"""Dispatches the request and on top of that performs request
pre and postprocessing as well as HTTP exception catching and
error handling.
TypeError: _wrapped_view() takes at least 1 argument (0 given)
The debugger caught an exception in your WSGI application. You can now look at the traceback which led to the error.
To switch between the interactive traceback and the plaintext one, you can click on the "Traceback" headline. From the text traceback you can also create a paste of it. For code execution mouse-over the frame you want to debug and click on the console icon on the right side.
You can execute arbitrary Python code in the stack frames and there are some extra helpers available for introspection:
dump() shows all variables in the frame
dump(obj) dumps all that's known about the object
Brought to you by DON'T PANIC, your friendly Werkzeug powered traceback interpreter.