jinja2

How can I create text forms with jinja?

半世苍凉 提交于 2020-01-25 11:58:25
问题 Background I would like to create a login form with jinja, Python, and HTML. The official document introduced an example of text forms using jinja. Problem However, I have two problems to create text forms with jinja. I cannot find "forms.html" document mentioned on the web page. There is no Python example to execute the code written in HTML and jinja. How can I fix my current code to execute the sample program of text form in jinja? Program <!DOCTYPE html> <html lang="en"> <head> <title

How to make html view/template that updates with new data from changed file

本秂侑毒 提交于 2020-01-25 07:02:53
问题 So I have a basic function called "follow" that monitors for file changes. That function yields each new line that is added to that file. That part works well, at least from what I see when testing it with print function. Now, I want to display those new lines as table rows in HTML template. This is my app main function: import time import json from flask import Flask, render_template app = Flask(__name__) def follow(myfile): myfile.seek(0, 2) while True: new_line = myfile.readline() if not

Flask Jinja2循环控制

≯℡__Kan透↙ 提交于 2020-01-25 01:44:24
目录 描述 Jinja2循环控制语法 使用示例 注意事项 描述 Jinja2模板中的条件控制语句(for)可以控制前端逻辑显示。 Jinja2循环控制语法 Jinja2的循环控制与Python类似,但还是有一些不同: {% for condition %} body... {% endfor %} 每个循环控制语句块结束后都要另起一行加上 {% endfor %},否则服务器会报错500。 使用示例 在页面中循环打印列表中的每个元素。 HTML文件: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Jinja2 Circulation Control</title> </head> <body> <ul> {% for product in products %} <li>{{product}}</li> {% endfor %} </ul> </body> </html> Python脚本: from flask import Flask, render_template app = Flask(__name__) @app.route("/") def index(): products = ["iphoneX", "MacBook Pro", "Huawei"] kwargs = {

Distinguish between types in jinja2

时光怂恿深爱的人放手 提交于 2020-01-24 20:31:05
问题 I have a HTML/jinja2 template that I am using to display data in the form of a table. The data for the table may come in different ways, and I want the template to be able to handle both types using if statements. the type(x) function in python does not work in this language. an array of dictionaries (list of dictionaries) an array of arrays (list of lists) a part of the template: {% block page_content %} <input type="text" id="search" placeholder="Type to search"> <table id="table" class=

reading from joined query in flask-sqlalchemy

扶醉桌前 提交于 2020-01-24 12:43:06
问题 After successfully joining two db tables, I'm trying to read the data from the 2nd table by addressing the first. I'm addressing opinion.topic_name from my jinja2 template, but nothing is returned. How can I access the Topic.topic_name value from the joined query? view @main.route('/', methods=['GET', 'POST']) def index(): form = IndexForm() opinions = [] if form.validate_on_submit(): opinions = Opinion.query .filter_by(party_id=form.party.data) .filter_by(topic_id=form.topic.data) .join(

Jinja2 Template - for loop

白昼怎懂夜的黑 提交于 2020-01-24 02:57:08
问题 didn't find another post which has the similar problem, I'm trying to generate some checkboxes with flask and wtforms, at the moment I've got this piece of code: <div class="control-group"> <p><strong>Check the enabled BRI Ports</strong></p> <label class="checkbox inline"> {{ form.bri1(value=1) }} {{ form.bri1.label }} </label> <label class="checkbox inline"> {{ form.bri2(value=1) }} {{ form.bri2.label }} </label> <label class="checkbox inline"> {{ form.bri3(value=1) }} {{ form.bri3.label }}

Is Jinja2 documentation out of date?

风流意气都作罢 提交于 2020-01-23 16:40:25
问题 I am getting 2 errors by doing simple things that follow the documentation here http://jinja.pocoo.org/docs/templates/ : {% if lang == 'fr' %} bonjour {% elif lang == 'en' %} hello {% endif %} TemplateSyntaxError: Invalid block tag: 'elif', expected 'else' or 'endif' and {% extends "skeleton.html" %} {% block a_name %} {{ super() }} I am extended {% endblock %} where skeleton.html contains {% block a_name %} hi I am skeleton {% endblock %} TemplateSyntaxError: Could not parse the remainder: '

jinja2 link to static files

断了今生、忘了曾经 提交于 2020-01-23 15:58:44
问题 I am trying to understand how to create a link to static files in jinja2. Everything I look up relates to Flask whereas I am using just webapp2 at this stage. My main.py file looks as follows: import os import urllib from google.appengine.api import users from google.appengine.ext import ndb import jinja2 import webapp2 JINJA_ENVIRONMENT = jinja2.Environment( loader=jinja2.FileSystemLoader(os.path.dirname(__file__)), extensions=['jinja2.ext.autoescape'], autoescape=True) class MainPage

jinja2 link to static files

不想你离开。 提交于 2020-01-23 15:56:06
问题 I am trying to understand how to create a link to static files in jinja2. Everything I look up relates to Flask whereas I am using just webapp2 at this stage. My main.py file looks as follows: import os import urllib from google.appengine.api import users from google.appengine.ext import ndb import jinja2 import webapp2 JINJA_ENVIRONMENT = jinja2.Environment( loader=jinja2.FileSystemLoader(os.path.dirname(__file__)), extensions=['jinja2.ext.autoescape'], autoescape=True) class MainPage

jinja2 link to static files

孤人 提交于 2020-01-23 15:54:17
问题 I am trying to understand how to create a link to static files in jinja2. Everything I look up relates to Flask whereas I am using just webapp2 at this stage. My main.py file looks as follows: import os import urllib from google.appengine.api import users from google.appengine.ext import ndb import jinja2 import webapp2 JINJA_ENVIRONMENT = jinja2.Environment( loader=jinja2.FileSystemLoader(os.path.dirname(__file__)), extensions=['jinja2.ext.autoescape'], autoescape=True) class MainPage