jinja2

How to add Bootstrap Validation to WTForms

南楼画角 提交于 2020-07-19 16:37:59
问题 I am using WTForms in conjunction with Flask and I would like to integrate the Bootstrap Form Validation for errors in my form. I have a basic login form setup something like this: class LoginForm(FlaskForm): """Login form.""" email = EmailField( "Email Address", validators=[DataRequired(), Email(), Length(min=6, max=40)] ) password = PasswordField( "Password", validators=[DataRequired()] ) def __init__(self, *args, **kwargs): """Create instance.""" super(LoginForm, self).__init__(*args, *

Escaping jinja template for javascript place holder

99封情书 提交于 2020-07-16 10:20:32
问题 I want to add a javascript placeholder and place a variable in a jinja template for href place of a link tag . I have tried {% raw %} method and &quot: method but it seems that the {% raw %} method throws an exception as the following "% as an unidentified character" The code is given below, help would be much appreciated or any other method to accomplish the task. for(i =0 ; i<= channels.length -1;i++){ console.log(channels[i]) const li = document.createElement("li"); li.innerHTML = `<a href

Escaping jinja template for javascript place holder

寵の児 提交于 2020-07-16 10:19:03
问题 I want to add a javascript placeholder and place a variable in a jinja template for href place of a link tag . I have tried {% raw %} method and &quot: method but it seems that the {% raw %} method throws an exception as the following "% as an unidentified character" The code is given below, help would be much appreciated or any other method to accomplish the task. for(i =0 ; i<= channels.length -1;i++){ console.log(channels[i]) const li = document.createElement("li"); li.innerHTML = `<a href

Flask: Results of the query is not being displayed on the webpage using jinja (user_data)

跟風遠走 提交于 2020-07-10 07:40:10
问题 I have a fairly basic flask set up (been coding using sublime text). For testing purposes, I am now trying to run the following .py file. It contains a query that generates the data: user_data. I am trying to see what the result of that data is. from datetime import datetime from flask import Flask, render_template, url_for import sqlite3 app = Flask(__name__) db_locale='users.db' def query_comments(): connie=sqlite3.connect(db_locale) c=connie.cursor() c.execute(""" SELECT * FROM comments ""

How can I get execution_date in dag?? the outside of operator?

对着背影说爱祢 提交于 2020-07-08 12:26:50
问题 How can I get an execution_date parameter in outside of dag? execution_min = "{{execution_date.strftime('%M') }}" if execution_min == '00': logging.info('**** ' + "YES, It's 00") final_task = DummyOperator( task_id='task_y00', ... dag=dag ) else: logging.info('**** ' + "NOPE!!!") final_task = DummyOperator( task_id='task_n00', ... dag=dag ) I want to set a task stream with dynamically with execution_date (especially minute) But Jinja template won't work with template_fields = ['execution_date

Render an editable table using Flask, Jinja2 templates, then process the form data returned

强颜欢笑 提交于 2020-07-04 06:36:24
问题 I'm using Flask and Jinja2 and I need to make an editable table with multiple rows. This is what the table will look like: And here's HTML for that: <form action="/support/team-members-update" method="post"> <table> <tbody><tr> <th>Name</th> <th>Id</th> <th>Inbox Share</th> </tr> <tr> <td>Ben</td><td>55555</td><td><input type="text" name="share_55555" value="0"></td></tr> <tr> <td>Steve</td><td>66666</td><td><input type="text" name="share_66666" value="1"></td></tr> <tr> <td>Harry</td><td

How to loop through related tables with Jinja2?

☆樱花仙子☆ 提交于 2020-06-29 06:39:29
问题 Description I am learning Flask and I created a database which contains 3 tables which are related between them: Company: info about the company I worked for (made up :) ) Job: info about the role I had in each company Task: info about the tasks i had in each job i had in each company. Here is the code: from flask import Flask, render_template from flask_sqlalchemy import SQLAlchemy from datetime import datetime app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///work

Python list indices integers or slices

拈花ヽ惹草 提交于 2020-06-29 04:28:06
问题 I know there is a thread about this, I read it through multiple times and tried what was answered but it did not work for me. Now my Python code looks like this: import requests from flask import Flask, render_template, url_for product_names = [list of products, removed it as it makes thread longer, I have these here just to see what products there are] app = Flask(__name__) @app.route('/') def price(): f = requests.get( "https://api.hypixel.net/skyblock/bazaar?key=[supposed to be secret]")

Combine two lists and alternating the result in Jinja?

青春壹個敷衍的年華 提交于 2020-06-28 03:41:20
问题 I'm working on a sandboxed CMS so I can't run any pythonic code, other than versions of Jinja. I am pulling my lists from a database where I split them based on having a field = a certain value. {# rows = command to pull from db #} {% set row_one = rows|selectattr('resource','equalto','One') %} {% set row_two = rows|selectattr('resource','equalto','Two') %} {# Sets my empty array #} {% set newobj = [] %} From here, console logging either Row one/two will result in showing me only those items

replace block within {{ super() }}

本秂侑毒 提交于 2020-06-27 08:32:34
问题 I have a base template which includes a block for the default <head> content. Within the head block, there's a block for the <title> . For example, in the base file I would have: <head> {% block head %} {% block title %}<title>An App</title>{% endblock title %} <script src="somescript.js"></script> {% endblock head %} </head> In the child template, I would like to include everything that was in the head block from the base (by calling {{ super()) }} and include some additional things, yet at