jinja2

How do I fix this Gets server error, which is causing display issues?

杀马特。学长 韩版系。学妹 提交于 2019-12-13 08:27:56
问题 The list in the left column of ontariocourts311.ca, along with the body of the page under the image intermittently fail to display (which is 'fixed' by refreshing the page). I'm a Noob, and have tried various versions of the return statement without success. Error: 2019-06-05 16:39:26,765: Exception on / [GET] Traceback (most recent call last): File "flask/app.py", line 2311, in wsgi_app response = self.full_dispatch_request() File "flask/app.py", line 1834, in full_dispatch_request rv = self

Access Array from javascript to jinja

百般思念 提交于 2019-12-13 07:56:29
问题 how do i read an array from javascript to jinja template: <script type="text/javascript"> var x =0; function ActionDeterminator() { x=x+1; document.getElementById("me").innerHTML=x; var $label = $('input[id = optionD]').next(); $label.text(x); alert('{{option_D[0]}}'); return true; } </script>> when i use the code above.. it works pretty well.but when i want to put the variable x like this: <script type="text/javascript"> var x =0; function ActionDeterminator() { x=x+1; document

Minify JavaScript code containing Jinja2 expressions with the Closure Compiler

╄→尐↘猪︶ㄣ 提交于 2019-12-13 05:06:18
问题 I pass a JSON-encoded dictionary from Python 3 to Jinja2 template and assign it to a JavaScript variable. My template is as follows <script> var a = {{ json_dict }}; // is rendered as `var a = {"key": "value"};` </script> This works as expected, but I'd like to minify JavaScript code containing Jinja2 expressions using Closure Compiler, which currently throws predictable errors like JSC_PARSE_ERROR: Parse error. '}' expected at line 2 character 9 var a = {{ json_dict }}; What are my options?

display friends name by Flask Many-to-many sqlalchemy

泪湿孤枕 提交于 2019-12-13 04:47:31
问题 I have app that can make friends I am able to count friends and display it in profile.html But when I try to print the name of friends It doesn't work(It use flask-sqlalchemy) model.py: friends = db.Table('friends', db.Column('user_id', db.Integer, db.ForeignKey('user.id')), db.Column('friend_id', db.Integer, db.ForeignKey('user.id')) ) 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)

How do you store the request.form to db through wtforms or error in sqlalchemy update?

假装没事ソ 提交于 2019-12-13 04:23:20
问题 This is following on from this question: SQLalchemy/wtforms update issue - 400 bad request I have a flask framework Issue When I submit the form the flash message comes up saying prediction added although when I query the db nothing has changed?? Can anyone spot where I'm going wrong? What am I trying to achieve Users are able to view their predictions making changes to current predictions. If there are no new predictions then they can submit new predictions. views # Predictor - User makes

Jinja2 templating boolean variables cleanly

╄→尐↘猪︶ㄣ 提交于 2019-12-13 03:59:50
问题 The following code selects all 3 of the options (though only perhaps one is desirable). <select id="example-getting-started" name="test" multiple="multiple"> <option value="cheese" selected="NO">Cheese</option> <option value="tomatoes" selected>Tomatoes</option> <option value="mozarella" selected="maybe">Mozzarella</option> <option value="mushrooms">Mushrooms</option> <option value="pepperoni">Pepperoni</option> <option value="onions">Onions</option> </select> It's not hard to convert this to

Jinja2 extension outputs escaped html instead of html tag

送分小仙女□ 提交于 2019-12-13 02:59:40
问题 I'm trying to write a simple jinja2 extension that'll render a <meta> tag in the page with some property and content attr. It looks something like this: from jinja2 import nodes from jinja2.ext import Extension class MetaExtension(Extension): """ returns a meta tag of key, value >> env = jinja2.Environment(extensions=[MetaExtension]) >> env.from_string('{% meta "key", "value" %}').render() u'<meta property="keyword" content="value" />' """ # we'll use it in the template with tags = set(['meta

how to split value in Ansible with delimiter

回眸只為那壹抹淺笑 提交于 2019-12-13 02:53:58
问题 I am setting a fact in Ansible and that variable has a value with hyphens, like this " dos-e1-south-209334567829102380 ". i want to split , so i only get "dos-e1-south" Here is the play - set_fact: config: "{{ asg.results|json_query('[*].launch_configuration_name') }}" - debug: var: config 回答1: another option is ansibles regular expression filter, you find here: https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#regular-expression-filters vars: var: dos-e1-south

Create a string using Jinja2 template

倾然丶 夕夏残阳落幕 提交于 2019-12-13 02:49:23
问题 I want to convert this variable: default_attr: attr1 : - "1" nexatt : - "b" ... to "attr=1,nextattr=b,..." (i.e.comma separated string) using Jinja template. Is there a possible way to do this? - name: Reading the attributes set_fact: app_attributes: | {% set attributes = " " -%} {% for key in default_attr.keys() -%} {% for value in default_attr[key] -%} {% attributes: "{{ attributes }} + [{'key=value'}]" -%} {%- endfor %} {%- endfor %} {{ attributes }} The error I get is shown below: fatal:

Jinja2 url generation

百般思念 提交于 2019-12-13 01:37:14
问题 <a href="{{ url('affiliate', affiliate=object.slug) }}">{{ object.name }} </a> Cause an error: reverse() got an unexpected keyword argument 'affiliate' 回答1: As your url() function seem to be an alias to the Django's reverse() , the function signature is different from the regular template tag. So just use the reverse() syntax: <a href="{{ url('affiliate', args=[object.slug]) }}">{{ object.name }}</a> 来源: https://stackoverflow.com/questions/34712469/jinja2-url-generation