jinja2

Reading a CSV file in Flask and iterating through Jinga2

岁酱吖の 提交于 2021-01-28 10:12:22
问题 I am trying to display data on my web app from a CSV file using Flask. The below code reads my CSV file and assigns stocklist as the variable for my data. In the HTML code below it, using jinga logic, I iterate through stocklist however my CSV columns are returned as rows (see sample output and pic). How do I display the rows correctly? My python function: @app.route('/stocks') def Stocks(): filename = 'stock_scraper - dev.csv' data = pandas.read_csv(filename, header=0) stocklist = list(data

Add a formatter (beautifier) to django-html files in Visual Studio Code

混江龙づ霸主 提交于 2021-01-28 09:40:31
问题 I'm using the Django extension for intellisense and syntax highlighting on Jinja templates (VS Code) but cannot figure out how to use my default formatter (HookyQR Beautify) to beautify/format my django-html files. Would that be possible? 回答1: I need to use beautify only for django-html files, I've got prettier working for js, html, css then flake8 and autopep8 for python, for django-html prettier wrongly formats jinja template strings, so I disabled the django-html from pettier languages and

Bootstrap modals not showing correctly when using Jinja templates

帅比萌擦擦* 提交于 2021-01-28 08:54:45
问题 While using Jinja templates, Bootstrap modals do not show properly. Either they show without disabling the background or they show disabled (and can't be closed). Including a CSS z-index didn't work. Changing the JavaScript code to open the modal manually didn't work. 回答1: All modals need to be placed outside of your <body> . If you place the modals inside of your main jinja2 {%block content%} , they have a tendency to behave oddly. Try the following: template.html - this is your main jinja2

Bootstrap modals not showing correctly when using Jinja templates

若如初见. 提交于 2021-01-28 08:43:58
问题 While using Jinja templates, Bootstrap modals do not show properly. Either they show without disabling the background or they show disabled (and can't be closed). Including a CSS z-index didn't work. Changing the JavaScript code to open the modal manually didn't work. 回答1: All modals need to be placed outside of your <body> . If you place the modals inside of your main jinja2 {%block content%} , they have a tendency to behave oddly. Try the following: template.html - this is your main jinja2

How can I use Jinja2 to group articles by date and paginate in Pelican?

孤者浪人 提交于 2021-01-28 04:44:09
问题 I'm using the Pelican static site generator to create a high-volume blog. Pelican themes paginate the index page, showing a list of post titles and summaries, sorting the posts by date. Here's an example of how this is accomplished, from the bootstrap theme: {% if articles %} {% for article in (articles_page.object_list if articles_page else articles) %} <div class='article'> <h2>{{ article.title }}</h2> <div class="well small">{% include "metadata.html" %}</div> <div class="summary">{{

Bootstrap Modal not appearing - jinja2

那年仲夏 提交于 2021-01-28 03:40:26
问题 I'm the thousandth person to ask a similar question, so I'm certain it's something simple. First time working with boostrap / jinja in Chrome. Simply put, the button is there, but clicking it does nothing. The data is all populating from Jinja just fine, and the jinja is rendering out the for loops properly, with matching id's between target calls and div id's. **EDIT: After following the suggestion of looking at this URL: https://getbootstrap.com/docs/5.0/components/modal/#usage and cutting

Jinja: loop to create form fields with same name but the last character

随声附和 提交于 2021-01-28 03:30:25
问题 I am using Flask and I have a WTF form with 12 input fields named like sold_1, sold_2,..., sold_12. I would like to generate these fields in Jinja using a loop like: {% for r in range(1, 13) %} {{ form.sold_ }}{{ r }} {% endfor %} or a similar syntax, but it doesn't work. I solved it in a quite convoluted way as follows: {% set tmp = "sold_x" %} {% for r in range(1, 13) %} {{ form[tmp | replace('x', r)] }} {% endfor %} but I wonder whether there is a cleaner way. Thanks 回答1: You could use

Bootstrap Modal not appearing - jinja2

夙愿已清 提交于 2021-01-28 02:19:01
问题 I'm the thousandth person to ask a similar question, so I'm certain it's something simple. First time working with boostrap / jinja in Chrome. Simply put, the button is there, but clicking it does nothing. The data is all populating from Jinja just fine, and the jinja is rendering out the for loops properly, with matching id's between target calls and div id's. **EDIT: After following the suggestion of looking at this URL: https://getbootstrap.com/docs/5.0/components/modal/#usage and cutting

Rendering HTML emails with inline CSS using Jinja

回眸只為那壹抹淺笑 提交于 2021-01-26 09:46:55
问题 As you know, if you are going to send an HTML email, all CSS styling must be inline on the elements themselves e.g. <p style='font-family: Helvetica'> Is there a way I can use Jinja to easily create HTML email bodies from Jinja templates without repeating CSS styles many times in a single template? I think of setting these styles to variables e.g. {% set FONT_STYLE = 'font-family: Helvetica; color: #111' %} and then in the template I can do <p style='{{ FONT_STYLE }}'>My paragraph here.</p>

Split a pandas dataframe using unique; Render as separate tables in Jinja2

强颜欢笑 提交于 2021-01-25 06:52:28
问题 I'm working on a project wherein I load a .csv file into a pandas dataframe and make a .PDF report, using Python 3.6 + pandas + jinja2 + weasyprint. csv -> pandas -> jinja2 -> weasyprint Here's my challenge: One of pandas dataframes contains info that I want to split by the unique entries in one of its columns, and then display separate tables in jinja2 for each of those splits. Sample dataframe: Clothing Color Size 0 Shirt Blue M 1 Shirt Blue L 2 Shirt Black L 3 Pants Black L 4 Pants Blue XL