I am using Flask, jinja together with Mustachjs.
In order to get the job done I am using the {% raw %} tag.
Now, it is a multi-languages application and I use Babel.
How can I do :
{% raw %}
<script id="details" type="text/template">
<table class="table" >
<thead>
<tr>
<th>**{{gettext('col1')}}</th>
<th>**{{gettext('col2')}}</th>
<th>**{{gettext('col6')}}</th>
</tr>
</thead>
<tbody>
{{#skyrsla}}
<tr>
<td> {{index}}</td>
<td> {{nafn}}</td>
<td> {{mean_growth_index}}</td>
</tr>
{{/skyrsla}}
</tbody>
</table>
</script>
{% endraw %}
Since it is between raw tags, the Babel extension does not detect {{gettext('col1')}
Is there a way to alter the configuration of Babel.
My actual configuration looks like :
[python: **.py]
[jinja2: **/templates/**.html]
extensions=jinja2.ext.autoescape,jinja2.ext.with_
Simply end your raw blocks between calls to gettext:
{% raw %}
<script id="details" type="text/template">
<table class="table" >
<thead>
<tr>
<th>**{% endraw %}{{gettext('col1')}}{% raw %}</th>
<th>**{% endraw %}{{gettext('col2')}}{% raw %}</th>
<th>**{% endraw %}{{gettext('col6')}}{% raw %}</th>
</tr>
</thead>
<tbody>
{{#skyrsla}}
<tr>
<td> {{index}}</td>
<td> {{nafn}}</td>
<td> {{mean_growth_index}}</td>
</tr>
{{/skyrsla}}
</tbody>
</table>
</script>
{% endraw %}
Related
I have he following data_analytics.html` which in the end provides the
view:
{% extends 'base.html' %} {% block title %}Home{% endblock %}
{% block content %}
<!-- <h1 align="center" >Your Files</h1> -->
<br />
<table class="table table-bordered table-hover">
<caption> Files Uploaded</caption>
<tr>
<th class="table-light"> # </th>
<th class="table-light">File Name</th>
<th class="table-light">Date</th>
<th class="table-light">Access Data</th>
</tr>
{% for file in csv_file %}
<tr>
<!-- <td>{{ file.id }}</td> -->
<th scope="row">1</th>
<td>{{ file.data }}</td>
<td>{{ file.date }}</td>
<td>View Data</td>
{%endfor%}
</table>
{% endblock %}
Is there a way that when the user clicks on the link to have displayed the content of the .csv file using python/flask ?
Tried to create a function that redirects to an url_for but not working`
try this:
In this 'a' put a 'target="_blank"'
View Data
And, in the python let's create a new function:
from flask import send_from_directory
#app.route('/csv')
def see_file():
return send_from_directory(directory='static', path='files/cheat_sheet.pdf')
Just change the path and the directory. And the file is going to open in a new tab.
I have 3 lists of data that i would like to print out as a Table in HTML.
Lists
ipaddress [10.1.1.0,10.1.1.1,10.1.1.2,10.1.1.3]
State [Full,Full,Full,Full]
Interface [ge0,ge1,ge2,ge3]
ID [ 0,1,2,3]
I would like to Print above rows as a table under Table Column as rows.
Table Header
Address Interface State ID
I cant seem to figure out the proper for loops logic to print this as a table, here is what i have currently.
{%extends "home/layout.html"%}
{% block body%}
<h1 style="text-align:center;">Here is the Inventory </h1>
<li> {{ospfneighboraddress}}</li>
<table class="table table-striped">
<thead>
<tr>
<th scope="col">Address</th>
<th scope="col">Interface</th>
<th scope="col">State</th>
<th scope="col">ID</th>
</tr>
</thead>
<tbody>
{% for ospfaddress in ospfneighboraddress %}
<tr>
<td>{{ ospfaddress }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{%endblock%}
ospfneighboraddress is the first IP address list, rest are also lists
Here are other list names:
ospfneighborinterface
ospfneighborstate
ospfneighborID
How do print next three lists for each IP address ?
Here you go!
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<table border="1">
<tr>
<th>Address</th>
<th>Interface</th>
<th>State</th>
<th>ID</th>
</tr>
<tr>
<td>10.1.1.0</td>
<td>ge0</td>
<td>Full</td>
<td>0</td>
</tr>
<tr>
<td>10.1.1.1</td>
<td>ge1</td>
<td>Full</td>
<td>1</td>
</tr>
<tr>
<td>10.1.1.2</td>
<td>ge2</td>
<td>Full</td>
<td>2</td>
</tr>
<tr>
<td>10.1.1.3</td>
<td>ge3</td>
<td>Full</td>
<td>3</td>
</tr>
</table>
</body>
</html>
Details:
Client framwork: Django
Web server: Python + Flask
I have an HTML page which rendered with a data array.
Each item in the array contains some fields. And one of the fields is a json object.
In order to improve the visibility of the json i've converted the json obj to html table.
Currently it's does't work.
The results (on the browser) looks like that:
PasswordPolicy <table border="1"><tr><th>MinimumPasswordLength</th><td>16</td></tr><tr><th>RequireSymbols</th><td>True</td></tr><tr><th>Re
Flask code:
#app.route("/PasswordPolicy", methods=["GET"])
#login_required
def get_password_policy():
get_table_content = list(db_object.get_password_policy())
search_event = request.args.get('searchquery')
at_type = request.args.get('audittype')
print("**************")
for e in get_table_content:
print("Before:")
print(e['PasswordPolicy'])
e['PasswordPolicy'] = json2html.convert(json = e['PasswordPolicy'])
print("After:")
print(e['PasswordPolicy'])
print("get_table_content:")
print(get_table_content[0])
print("**************")
return render_template(
'soc2/password_policy.html',
get_list=get_table_content
)
Html content:
<table id="datatable-buttons" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
<thead>
<tr class="headings">
<th class="column-title">BusinessUnit </th>
<th class="column-title">ControllerNumber </th>
<th class="column-title">PasswordPolicy </th>
</tr>
</thead>
<tbody>
{% for elements in get_list %}
<tr class="even pointer">
<td>
{{ elements["BusinessUnit"] }}
</td>
<td>
{{ elements["ControllerNumber"] }}
</td>
<td>
{{ elements["PasswordPolicy"] }}
</td>
</tr>
{% endfor %}
</tbody>
</table>
The question is how to tell to the browser to parse the table as html instead of simple string
You can use safe like so: {{ your_html_string | safe }}
I have data:
data =
[
{
"name":"bolb",
"category_name":"Electronics",
"size":"34",
"price":"890",
"currency_name":"Us",
},
{
"name":"bolb",
"category_name":"Electronics",
"size":"2",
"price":"9099",
"currency_name":"Us",
}
]
I need to show this data into template like as below.
<table>
<tbody>
<tr>
<td>Category Compare</td>
<td>bolb</td>
<td>bolb asun</td>
</tr>
<tr>
<td>price </td>
<td>890</td>
<td>9099</td>
</tr>
<tr>
<td>category_name</td>
<td>Electronics</td>
<td>Electronics</td>
</tr>
<tr>
<td>currency_name</td>
<td>Us</td>
<td>Us</td>
</tr>
</tbody>
</table>
My desire output table vertically with dynamic. I have added image also for clarification. Can i change my variable data or i can do it using for loop.Please suggest best idea or code will be appreciate.
This is my output image:
you may do something like this:
<table>
<tbody>
<tr>
<td>Category Compare</td>
{% for i in data %}
<td>{{i.name}}</td>
{% endfor %}
</tr>
<tr>
<td>price </td>
{% for i in data %}
<td>{{i.price}}</td>
{% endfor %}
</tr>
<tr>
<td>category_name</td>
{% for i in data %}
<td>{{i.category_name}}</td>
{% endfor %}
</tr>
<tr>
<td>currency_name</td>
{% for i in data %}
<td>{{i.currency_name}}</td>
{% endfor %}
</tr>
</tbody>
</table>
I have a table that displays information through a list of dictionaries.
This is the program :
<div class = "col-md-8" >
<table class="table table-bordered table-striped table-hover">
<thead> <!-- En-tĂȘte du tableau -->
<tr>
<th> Host Name </th>
<th> Hardware </th>
<th> Fixed-Address </th>
<th> Comment </th>
<tr>
</thead>
<tbody> <!-- Corps du tableau -->
{% for item in items %}
<tr id="confirm">
{% for key in [ 'host','hardware','fixed_address','comment' ] %}
<td> {{ item[key].decode('utf-8') }}</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
</div>
What I would like to do is to be able to modify it or add a new entry, that's not what I am going to ask here because before that I need to do the following:
Basically, I need to make every row act as a link, when I click on it (the row) I should be redirected to a web page with web forms and those web forms will be filled with the data from the table cells.
How can I do it? Thanks beforehand.
Do something like this.
<thead> <!-- En-tĂȘte du tableau -->
<tr>
<th> Host Name </th>
<th> Hardware </th>
<th> Fixed-Address </th>
<th> Comment </th>
<th> View </th>
<tr>
</thead>
<tbody> <!-- Corps du tableau -->
{% for item in items %}
<tr id="confirm">
{% for key in [ 'host','hardware','fixed_address','comment' ] %}
<td> {{ item[key].decode('utf-8') }}</td>
{% endfor %}
View
</tr>
{% endfor %}
</tbody>
</table>
</div>
That function inside url_for should be the function which displays data and should renders page for displaying data.