0

在我的代码中,我试图将 Jinja2 模板中的两个变量传递给烧瓶。到目前为止,这就是我所做的:

<th><a href="{{ url_for('admin.edit', title=post.title ,url=prop.url) }}">{{ post.url }}    </a></th>

在我的烧瓶视图中,它甚至在到达 get 方法之前就出错了:

 def get(self, title, url):
    print "geturl"

我从调试器得到的错误是 get() 正好需要 3 个非关键字参数(给定 2 个)

File "/Users/kimmy/Documents/Flask+MongoDB/flaskapp/lib/python2.6/site-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/Users/kimmy/Documents/Flask+MongoDB/flaskapp/lib/python2.6/site-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/Users/kimmy/Documents/Flask+MongoDB/flaskapp/lib/python2.6/site-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/Users/kimmy/Documents/Flask+MongoDB/flaskapp/lib/python2.6/site-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/Users/kimmy/Documents/Flask+MongoDB/flaskapp/lib/python2.6/site-packages/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Users/kimmy/Documents/Flask+MongoDB/flaskapp/lib/python2.6/site-packages/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/Users/kimmy/Documents/Flask+MongoDB/flaskapp/lib/python2.6/site-packages/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/Users/kimmy/Documents/Flask+MongoDB/flaskapp/lib/python2.6/site-packages/flask_debugtoolbar/__init__.py", line 104, in dispatch_request
return view_func(**req.view_args)
File "/Users/kimmy/Documents/Flask+MongoDB/tumblelog/auth.py", line 26, in decorated
return f(*args, **kwargs)
File "/Users/kimmy/Documents/Flask+MongoDB/flaskapp/lib/python2.6/site-packages/flask/views.py", line 84, in view
return self.dispatch_request(*args, **kwargs)
File "/Users/kimmy/Documents/Flask+MongoDB/flaskapp/lib/python2.6/site-packages/flask/views.py", line 149, in dispatch_request
return meth(*args, **kwargs)
TypeError: get() takes exactly 3 non-keyword arguments (2 given)

我使用的模板是:

{% extends "admin/base.html" %}
{% block content %}
  <table  class="condensed-table zebra-striped">
    <thead>
   <th>Title</th>
   <th>Url</th>
  <th>Date Added</th>
  <th>Actions</th>
</thead>
<tbody>

{% for post in posts %}
  <tr>


    <td>{{post.url}}</td>


    <th><a href="{{ url_for('admin.edit', title=post.title, url=post.url ) }}">{{ post.url }}</a></th>
    <td>{{ post.date_added}}</td>
    <!-- <td>{{ post.created_at.strftime('%Y-%m-%d') }}</td> -->
    <td><a href="{{ url_for("admin.edit", title=post.title , url=post.url ) }}" class="btn primary">Edit</a></td>
  </tr>
   {% endfor %}
{% endfor %}
</tbody>

4

0 回答 0