You can add a page break after every 24th barcode using: {% if count % 24 %}<div style="page-break-before: always;"></div>{% endif %} ...
You need to provide a full example, as extrapolating from the information given, the code works fine. Here's an example. from flask import Flask, render_template app = Flask(__name__) @app.route('/') def hello_world(): check = {'location_id': 1} locations = {1: "Baltimore, MD"} return render_template('example.html', locations=locations, check=check) if __name__ == '__main__': app.run() Then...
python,flask,jinja2,flask-sqlalchemy,jinja
The name you've chosen, is_friend, is probably causing some of your confusion. Something like friends is a bit clearer. You also don't need the back reference as each User already has the relationship. class User(db.Model): id = db.Column(db.Integer, primary_key = True) name = db.Column(db.String(50), index=True, unique= True) email = db.Column(db.String(50),index=True,...
The fix You need to add the fields to your class not your instance: def driver_template_schedue_form(ages, per_day=30, **kwargs): """Dynamically creates a driver's schedule form""" # First we create the base form # Note that we are not adding any fields to it yet class DriverTemplateScheduleForm(Form): pass # Then we iterate...
You should use the name of the view, not the URL it listens to. Views can listen to multiple URLs. You registered your view with: @app.route('/topic/<topic>') def questions(topic): # ... so the view is registered with the name questions. You need to use questions as the endpoint for url_for(), providing...
You still need to output the loop variables inside braces. {% for result in results %} <tr> <td>{{ result[0] }}</td> <td>{{ result[1] }}</td> <td>{{ result[2] }}</td> </tr> {% endfor %} Also, consider a nested for loop: {% for result in results %} {% for elem in result %} <td>{{elem}}</td> {%...
python,html,django,jinja2,jinja
You could loop through a hard-coded list of keys: <ul> {% for key in ('b', 'a', 'c') %} {% if key in my_dict %} <li>{{ key }} is {{ my_dict[key] }}</li> {% endif %} {% endfor %} </ul> Non-existing keys are handled by the if test....
The route parameter <number> is given to you as a string, not an integer. If you want Flask to give you a numeric value, tell it so in the route configuration: @app.route('/fib/<int:number>') See the Variable Rules section in the quickstart....
Jinja is not Python (if you need to be able to write arbitrary Python in your templates you will do better with Mako). Instead, you need to do the work in Python and pass the results to Jinja: data = [] for file_name in file_names: with open(file_name, 'r') as f:...
Filters are used with the |filter syntax: {% elif student.department|upper != "MATHS DEPARTMENT" %} Maths department {% endif %} or you can use the str.upper() method: {% elif student.department.upper() != "MATHS DEPARTMENT" %} Maths department {% endif %} Jinja syntax is Python-like, not actual Python. :-)...
What I needed was generator.context['foo'] = 'bar' ...
You can use the length filter: {% if some_var|length > 1 %} ...
Figured it out. Jinja2 doesn't seem to handle localization on its own, but django-jinja includes a built-in contrib that wraps django.contrib.humanize.templatetags. According to the documentation for that, format localization is respected using the |intcomma filter if L10n is enabled. To use it, add django_jinja.contrib._humanize to INSTALLED_APPS in settings.py: INSTALLED_APPS +=...
You can use the map() filter to apply a sum to each group, provided you extract the group list first: foo | groupby('a') | map(attribute='list') | map('sum', attribute='b') That's because map() takes the first argument as another filter, and the remainder of the arguments are passed to that filter, applying...
python,google-app-engine,jinja
Jinja is a layout language, don't try to do code tasks in that language. It's great doing loops and conditionals, not great for doing arithmetic. Calculate your average in the Python code and pass that value into your template....
Something like this shows a simple example. from flask import Flask, request, redirect app = Flask(__name__) # really look in db here or do whatever you need to do to validate this as a valid topic. def is_valid_topic(topic): if topic == "foo": return False else: return True @app.route('/') def index():...
flask,jinja2,flask-sqlalchemy,jinja
In user.html you call the variable contact. You probably want to call it user. {% for user in contact %} You'll also need to update the references to contact.id and contact.name. ...
No, you cannot pass general Python expression to filter in Jinja2 template The confusion comes from jinja2 templates being similar to Python syntax in many aspects, but you shall take it as code with completely independent syntax. Jinja2 has strict rules, what can be expected at which part of the...
yaml,jinja2,state,salt-stack,jinja
Choice of data source I would recommend targeting with pillars because they are managed centrally from Master = convenient, rather than static custom grains (which are configured distributively on each Minion) = inconvenient - see comparison summary here. Limitations of configuration files The nodegroups are specified in Salt configuration file...
Never mind, I got it. I needed to use safe to escape the code. Example: <script> var name = JSON.parse('{{ data | safe }}'); alert(name); </script> ...