jinja2

In Ansible, how to use a variable inside a variable definition that uses filters

喜你入骨 提交于 2019-12-22 04:16:06
问题 I want to extract a few regex matches out of a URL. The only way I could do this was following: - name: Set regex pattern for github URL set_fact: pattern="^(git\@github\.com\:|https?\:\/\/github.com\/)(.*)\/([^\.]+)(\.git)?$" - name: Extract organization name set_fact: project_repo="{{ deploy_fork | regex_replace( "^(git\@github\.com\:|https?\:\/\/github.com\/)(.*)\/([^\.]+)(\.git)?$", "\\3" ) }}" when: deploy_fork | match( "{{ pattern }}" ) With this approach, I'm able to reuse the variable

Python - Flask: render_template() not found [duplicate]

亡梦爱人 提交于 2019-12-22 02:07:06
问题 This question already has answers here : Flask raises TemplateNotFound error even though template file exists (10 answers) Closed 4 years ago . I'm new in flask. I have this code: Will you give me an advice what I'm doing wrong? Thanks from flask import Flask from flask import request from flask import render_template app = Flask(__name__) @app.route('/') def my_form(): return render_template('my-form.html') @app.route('/', methods=['POST']) def my_form_post(): text = request.form['text']

webapp2, Jinja2: how to cut large html file into multiple html files

若如初见. 提交于 2019-12-21 22:00:52
问题 When I blog, I like to separate each blog-post into its own .html file (is that ok?) This prevents the file getting too big, and makes it easy to go back and edit a previously written blog post if need be. Occasionally the blog post will contain css/js/ajax/template variables. But on my website, I like all the blog posts on one page (so I can scroll through them all, instead of going to a separate page for each post) Here is an html file that contains two blog posts: {% extends "base.html" %}

Flask and Jinja2 with bleach, image HTML not working

…衆ロ難τιáo~ 提交于 2019-12-21 20:30:04
问题 I have been creating a small blog for myself for a project, only I, as the user, can access the posting page. I had previously been following a Flask tutorial, the end product of which enables you to post HTML and pass it through the Jinja2 templating, using bleach and Markdown. In my models.py file, these are the allowed tags. @staticmethod def on_changed_body(target, value, oldvalue, initiator): allowed_tags = ['a', 'abbr', 'acronym', 'b', 'blockquote', 'code', 'em', 'i', 'li', 'ol', 'pre',

How to decode &#39 in flask with Jinja2 template [duplicate]

ε祈祈猫儿з 提交于 2019-12-21 14:21:24
问题 This question already has answers here : JavaScript raises SyntaxError with data rendered in Jinja template (2 answers) Closed 3 years ago . When I'm trying to write errors from wtforms in Jinja2 template, it returns undecoded quote. How can i fix it? {% if registrationForm.errors %} <script>swal("Error!", "{{ registrationForm.errors['password'] }}", "error")</script> {% endif %} Errors are equal to {'email': ['This field is required.'], 'username': ['This field is required.'], 'acceptTOS': [

HTML templating using Jinja2 No module named your app

谁说我不能喝 提交于 2019-12-21 09:26:47
问题 I am trying to create a html template in python using Jinja2. I have a templates folder with my 'template.html' but I don't know how to deal with environments or package loaders. I installed Jinja2. These my simple codes from jinja2 import Environment, PackageLoader env = Environment(loader=PackageLoader('ap', 'templates')) template = env.get_template('template.html') print template.render(title='hello') I get this error: File "a.py", line 3, in <module> env = Environment(loader=PackageLoader

Can't disable the autoescape in jinja2

孤者浪人 提交于 2019-12-21 07:09:12
问题 In GAE I use jinja2 with the autoescape, and everything works well. import jinja2 jinja_env = jinja2.Environment(loader = jinja2.FileSystemLoader(template_dir), autoescape = True) In one template I don't want the autoescape, so I tried to disable it like this: {% autoescape false %} {{content}} {% endautoescape %} When it's time to render this template I get the message Encountered unknown tag 'autoescape'. 回答1: Try this: {{ content | safe}} docs: Flask — Controlling Autoescaping Jinja2 —

How to render my select field with WTForms?

北慕城南 提交于 2019-12-21 05:28:07
问题 I have a select field that has certain elements faded and disabled that I would like to render with WTForms: <select name="cg" id="cat" class="search_category"> <option value='' >{% trans %}All{% endtrans %}</option> <option value='' style='background-color:#dcdcc3' id='cat1' disabled="disabled">-- {% trans %}VEHICLES{% endtrans %} --</option> <option value='2' {% if "2" == cg %} selected="selected" {% endif %} id='cat2' >{% trans %}Cars{% endtrans %}</option> <option value='3' {% if "3" ==

Flask-Babel localized strings within js

陌路散爱 提交于 2019-12-21 05:03:30
问题 I'm pretty new to both Python and Flask (with Jinja2 as template engine) and I am not sure I am doing it the right way. I am using Flask-Babel extension to add i18n support to my web application. I want to get localized strings from my js code, for instance: var helloWorld = gettext('Hello, world'); console.log(helloWorld); //should log a localized hello world message For this, I configured babel (babel.cfg): [python: **/**.py] [jinja2: **/**.html] extensions=jinja2.ext.autoescape,jinja2.ext

Add a nav bar to all templates

百般思念 提交于 2019-12-20 20:38:38
问题 I want to show a nav bar on every page. In PHP, I would write the nav bar then include it on the other pages. I tried to include or extend the nav bar template into the other templates, but it didn't work. It only outputs "This is the home page." How do I correctly include the nav bar in every template? layout.html <!doctype html> <html> <body> {% block navbar %} <style> body { margin: 0; padding: 0; } div{ background: #333; color: #f9f9f9; width: 100%; height: 50px; line-height: 50px; text