Title: How to pass multiple variables in Jinja2 template to Flask
Tags: python;flask;jinja2
Question: In my code im am trying to pass two variables from the Jinja2 template to flask.
So far this is what i have done:
<th&gt;<a href="{{ url_for('admin.edit', title=post.title ,url=prop.url) }}"&gt;{{ post.url }}    </a&gt;</th&gt;
and in my flask view it errors before it even hits the get method:
def get(self, title, url):
print "geturl"
The error i get from the debugger is get() takes exactly 3 non-keyword arguments (2 given)
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)
The template i am using is:
{% extends "admin/base.html" %}
{% block content %}
<table  class="condensed-table zebra-striped"&gt;
<thead&gt;
<th&gt;Title</th&gt;
<th&gt;Url</th&gt;
<th&gt;Date Added</th&gt;
<th&gt;Actions</th&gt;
</thead&gt;
<tbody&gt;
{% for post in posts %}
<tr&gt;
<td&gt;{{post.url}}</td&gt;
<th&gt;<a href="{{ url_for('admin.edit', title=post.title, url=post.url ) }}"&gt;{{ post.url }}</a&gt;</th&gt;
<td&gt;{{ post.date_added}}</td&gt;
<!-- <td&gt;{{ post.created_at.strftime('%Y-%m-%d') }}</td&gt; --&gt;
<td&gt;<a href="{{ url_for("admin.edit", title=post.title , url=post.url ) }}" class="btn primary"&gt;Edit</a&gt;</td&gt;
</tr&gt;
{% endfor %}
{% endfor %}
</tbody&gt;
Comment: yes i am using the based view, the code i have provided works with if i take out the url from the href tag and url from the get method

Comment: The url i input my browser is http://151.154.11.224:5000/admin/Title/?url=Url

Comment: Are you using class based views? Otherwise, that `self` in your function signature is likely the problem.

Comment: What url template you use for this view and what url you input in browser for this exception?

Comment: possible duplication for http://stackoverflow.com/questions/6036082/call-a-python-function-from-jinja2

Comment: Can you provide a full traceback?



{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 0, 'CommentCount': 6, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2013:00:06/29/13', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<python><flask><jinja2>', 'Title': 'How to pass multiple variables in Jinja2 template to Flask', 'ViewCount': 3558, 'id': 17380499, 'user_AboutMe': '', 'user_AccountId': 2294676.0, 'user_DisplayName': 'Kimmy', 'user_Reputation': 3267.0, 'user_Views': 79.0, 'user_id': 2016434.0}}