-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
jinja2 template path dict in dict #164
Comments
Sorry, but your bug report is totally unclear. |
English not my native but i'll try to explain
if you look in example
https://github.com/aio-libs/aiohttp/blob/master/demos/polls/aiohttpdemo_polls/templates/index.html
you will see jinja template
<li><a href="{{ url('poll', parts={'question_id': question.id}) }}">{{
question.question_text }}</a></li>
in routes.py we define:
def setup_routes(app):
app.router.add_get('/', index)
app.router.add_get('/poll/{question_id}', poll, name='poll')
it setup route /poll/{question_id}
then when we process such template we run code in aiohttp_jinja2/helpers.py
@jinja2.contextfunction
def url_for(context, __route_name, **parts):
"""
filter for generating urls, see
http://aiohttp.readthedocs.io/en/stable/web.html#reverse-url-constructing-using-named-resources
Usage: {{ url('the-view-name') }} might become "/path/to/view" or
{{ url('item-details', id=123, query={'active': 'true'}) }} might
become "/items/1?active=true".
"""
app = context['app']
query = None
if 'query_' in parts:
query = parts.pop('query_')
url = app.router[__route_name].url_for(**parts)
if query:
url = url.with_query(query)
return url
#################################
app.router[__route_name].url_for(**parts) it's a
str('/poll/{question_id}').format_map(parts)
and format_map expect simple dict
we have { 'parts' : { 'question_id' : 1} }
and such construction doesn't work
2017-10-13 13:55 GMT+03:00 Andrew Svetlov <[email protected]>:
… Sorry, but your bug report is totally unclear.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#164 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AKMqAuF4ynMcHBTAtDX9F_XFjbGDbHgIks5sr0GpgaJpZM4P4UH_>
.
|
Re-read many times and still cannot figure out the problem. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Long story short
jinja2 template wrong dict
but we have { 'parts' : {RIGHT_DICT} } dict in dict
Expected behaviour
Actual behaviour
Steps to reproduce
/usr/lib/python3.6/site-packages/aiohttp_jinja2/helpers.py
Your environment
The text was updated successfully, but these errors were encountered: