jinja2

Flask: AttributeError: 'UnboundField' object has no attribute '__call__'?

孤街醉人 提交于 2021-02-09 02:56:09
问题 Why do I get this error? What is the UnboundField and what do I need to know in order to fix and avoid this problem in the future? Debug output when I visit http://127.0.0.1:5000/signup: AttributeError AttributeError: 'UnboundField' object has no attribute '__call__' Traceback (most recent call last) File "C:\Users\combatmath\Envs\default\lib\site-packages\flask\app.py", line 2000, in __call__ return self.wsgi_app(environ, start_response) File "C:\Users\combatmath\Envs\default\lib\site

Jinja2 check if value exists in list of dictionaries

孤人 提交于 2021-02-09 00:26:33
问题 I am trying to check if a value exists inside a list with dictionaries. I use flask 1.0.2. See example below: person_list_dict = [ { "name": "John Doe", "email": "johndoe@mydomain.com", "rol": "admin" }, { "name": "John Smith", "email": "johnsmith@mydomain.com", "rol": "user" } ] I found two ways to solve this problem, can you tell me which is better?: First option: jinja2 built-in template filter "map" <pre>{% if "admin" in person_list_dict|map(attribute="rol") %}YES{% else %}NOPE{% endif %}

Jinja2 check if value exists in list of dictionaries

你离开我真会死。 提交于 2021-02-09 00:24:58
问题 I am trying to check if a value exists inside a list with dictionaries. I use flask 1.0.2. See example below: person_list_dict = [ { "name": "John Doe", "email": "johndoe@mydomain.com", "rol": "admin" }, { "name": "John Smith", "email": "johnsmith@mydomain.com", "rol": "user" } ] I found two ways to solve this problem, can you tell me which is better?: First option: jinja2 built-in template filter "map" <pre>{% if "admin" in person_list_dict|map(attribute="rol") %}YES{% else %}NOPE{% endif %}

Generate HTML from HTML template in python?

我的梦境 提交于 2021-02-08 11:49:19
问题 I want to design my own HTML template with tags like JSP or Jade and then pass data from python to it and let it generate full html page. I don't want to construct document at python side like with DOM. Only data goes to page and page tempalte decides, how data lays out. I don't want to serve resulting pages with HTTP, only generate HTML files. Is it possible? UPDATE I found Jinja2, but I has strange boilerplate requirements. For example, they want me to create environment with env =

Jinja2 and Bootstrap carousel - “item active”

孤人 提交于 2021-02-08 10:22:54
问题 I'm new to Jinja and this is my first post here on Stack Overflow. I'm trying to loop through a gallery of images handled by bootstrap carousel/modal. I was able to let it work; <img> and <div> are rendered correctly, however I can't loop through the active element. Searching the web, I found that macros can help achieve it but I'm not familiar with using them. Here's the code I'm working on: <div class="modal fade" id="myModalGal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">

UndefinedError: 'current_user' is undefined

為{幸葍}努か 提交于 2021-02-07 13:59:09
问题 I have a app with flask which works before But Now I use Blueprint in it and try to run it but got the error so i wonder that is the problem Blueprint that g.user Not working? and how can I fix it Thnx :) app/layout/__ init __.py : from flask import Blueprint layout = Blueprint('layout', __name__) from . import view __ init __ .py from flask import Flask from flask.ext.sqlalchemy import SQLAlchemy from flask.ext.login import LoginManager import psycopg2 from config import basedir from config

Ansible/Jinja2 how to append key into list of dict

蹲街弑〆低调 提交于 2021-02-07 09:13:03
问题 I would like to have dictionary defined in ansible like this vhosts: git_branch_1: - { a: example.com, customer: a } - { a: example.com, customer: b } - { a: example.org, customer: a } git_branch_2: - { a: example.com, customer: x } - { a: example.org, customer: y } Some tasks I need to loop only over dict keys, this works fine - name: "just debug" debug: msg={{ item }} with_items: "{{ vhosts.keys() }}" But some tasks I would like to iterate over list from each key, and append the key as

Ansible/Jinja2 how to append key into list of dict

▼魔方 西西 提交于 2021-02-07 09:12:28
问题 I would like to have dictionary defined in ansible like this vhosts: git_branch_1: - { a: example.com, customer: a } - { a: example.com, customer: b } - { a: example.org, customer: a } git_branch_2: - { a: example.com, customer: x } - { a: example.org, customer: y } Some tasks I need to loop only over dict keys, this works fine - name: "just debug" debug: msg={{ item }} with_items: "{{ vhosts.keys() }}" But some tasks I would like to iterate over list from each key, and append the key as

why to use “ | safe” in jinja2 Python [duplicate]

◇◆丶佛笑我妖孽 提交于 2021-02-07 06:50:15
问题 This question already has answers here : Passing HTML to template using Flask/Jinja2 (6 answers) Closed 2 years ago . I am following a Flask tutorial where he is using " | safe " in jinja2 template. Why do we need this pipe symbol and safe? without using safe it prints all html tags. By using | safe , it shows proper formatting. Why does it work this way? Below is the jinja2 code: {% extends "layout.html" %} {% block body %} <h1>{{article.title}}</h1> <small>Written by {{article.author}} on {

How to debug Jinja2 template?

ぐ巨炮叔叔 提交于 2021-02-06 09:41:53
问题 I am using jinja2 template system into django. It is really fast and I like it a lot. Nevertheless, I have some problem to debug templates : If I make some errors into a template (bad tag, bad filtername, bad end of block...), I do not have at all information about this error. For example, In a django view, I write this : from jinja2 import Environment, PackageLoader env = Environment(loader=PackageLoader('main', 'templates')) def jinja(req): template = env.get_template('jinja.html') output