jinja2

jinja2 nested for loops two lists

孤人 提交于 2020-08-09 18:41:22
问题 I have the following code that is not rendering the way I would like on the html front end. {% for image in images %} {% for title in titles %} <div class="card" style="width: 18rem;"> <img src="{{image}}" class="card-img-top" alt="..."> <div class="card-body"> <h5 class="card-title">{{title}}</h5> <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p> <a href="#" class="btn btn-primary">Go somewhere</a> </div> {% endfor %} {%

Embed custom filter definition into jinja2 template?

随声附和 提交于 2020-08-06 12:47:32
问题 I'm writing some Jinja2 templates that I'd like to be able to reuse as painlessly as possible in tangentially related projects. I have a set of custom convenience filters that I'd like the templates to "carry around" with them. Is there a Jinja2 syntax for embedding filter definitions into a template itself? Or a mechanism for embedding any kind of pure Python function into a Jinja2 template that can act on variables passed into the template? I used to use mako, and there it was trivial to do

Set default value for select html element in Jinja template?

拥有回忆 提交于 2020-08-02 06:09:52
问题 I'm using flask/jinja in order to make a simple web application. I have a table of records which is taken from a db table, and is called by a webpage which loads the list of records. On each row there is a dropdown list (done using the select HTML tag) on a column. I realize the below code doesn't do what its supposed to, currently the last option (fourth) is automatically selected because of the selected tag. I've left it in to try show what I'm trying to implement. Ideally I'd want it to

Set default value for select html element in Jinja template?

二次信任 提交于 2020-08-02 06:08:53
问题 I'm using flask/jinja in order to make a simple web application. I have a table of records which is taken from a db table, and is called by a webpage which loads the list of records. On each row there is a dropdown list (done using the select HTML tag) on a column. I realize the below code doesn't do what its supposed to, currently the last option (fourth) is automatically selected because of the selected tag. I've left it in to try show what I'm trying to implement. Ideally I'd want it to

I am unable to install Jinja in Pycharm using pip3 install Jinja. How to solve this error?

♀尐吖头ヾ 提交于 2020-07-23 07:17:18
问题 $ pip3 install Jinja Collecting Jinja Using cached https://files.pythonhosted.org/packages/df/50/70f41c599cf0ace6c554b07108916513c70d0e950b0abb18c27a865df7a2/Jinja-1.2.tar.gz Complete output from command python setup.py egg_info: Traceback (most recent call last): File "", line 1, in File "/tmp/pip-build-zmxr6gb7/Jinja/setup.py", line 28 except DistutilsError, e: ^ SyntaxError: invalid syntax ---------------------------------------- Command "python setup.py egg_info" failed with error code 1

I am unable to install Jinja in Pycharm using pip3 install Jinja. How to solve this error?

烂漫一生 提交于 2020-07-23 07:16:34
问题 $ pip3 install Jinja Collecting Jinja Using cached https://files.pythonhosted.org/packages/df/50/70f41c599cf0ace6c554b07108916513c70d0e950b0abb18c27a865df7a2/Jinja-1.2.tar.gz Complete output from command python setup.py egg_info: Traceback (most recent call last): File "", line 1, in File "/tmp/pip-build-zmxr6gb7/Jinja/setup.py", line 28 except DistutilsError, e: ^ SyntaxError: invalid syntax ---------------------------------------- Command "python setup.py egg_info" failed with error code 1

I am unable to install Jinja in Pycharm using pip3 install Jinja. How to solve this error?

China☆狼群 提交于 2020-07-23 07:15:22
问题 $ pip3 install Jinja Collecting Jinja Using cached https://files.pythonhosted.org/packages/df/50/70f41c599cf0ace6c554b07108916513c70d0e950b0abb18c27a865df7a2/Jinja-1.2.tar.gz Complete output from command python setup.py egg_info: Traceback (most recent call last): File "", line 1, in File "/tmp/pip-build-zmxr6gb7/Jinja/setup.py", line 28 except DistutilsError, e: ^ SyntaxError: invalid syntax ---------------------------------------- Command "python setup.py egg_info" failed with error code 1

Webscraping information off website using python requests

坚强是说给别人听的谎言 提交于 2020-07-22 05:50:29
问题 Webscraping https://www.nike.com/w/mens-shoes-nik1zy7ok for shoes. Right now I can retrieve the shoes that initially load, and also the shoes that load as you scroll to the next page with the following code: import re import json import requests from bs4 import BeautifulSoup url = 'https://www.nike.com/gb/w/womens-shoes-5e1x6zy7ok' html_data = requests.get(url).text data = json.loads(re.search(r'window.INITIAL_REDUX_STATE=(\{.*?\});', html_data).group(1)) for p in data['Wall']['products']:

How to add Bootstrap Validation to WTForms

泪湿孤枕 提交于 2020-07-19 16:42:41
问题 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, *

How to add Bootstrap Validation to WTForms

纵然是瞬间 提交于 2020-07-19 16:38:51
问题 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, *