jinja2

Pass JavaScript variable to Flask url_for

北慕城南 提交于 2019-12-17 02:37:54
问题 I have an endpoint that takes a value in the url and produces some content that will be inserted into a div. I want to build the url with url_for using a JavaScript variable. However, $variable1 is passed as a string, rather than the value of variable1 . How can I pass the value of a JavaScript variable to url_for ? function myFunction() { var variable1 = "someString" $('#demo').load( "{{ url_for('addshare2', share = '$variable1') }}" ); } 回答1: You can't evaluate JavaScript in Jinja. You're

BuildError: Could not build url for endpoint 'user' with values ['nickname']. Did you forget to specify values ['page', 'username']?

与世无争的帅哥 提交于 2019-12-14 03:58:11
问题 I am getting the following error when I try to goto index.html on my site. The site was templated from https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-v-user-logins I modified it to take in usernames/passwords and got rid of openid. I went through and replaced nickname in the database with username and somehow it is still referencing it even after I have updated the database. I'm still new to this so please go easy. I searched for how to build url's and can't find anything I

Range not working in for loop

坚强是说给别人听的谎言 提交于 2019-12-14 03:06:49
问题 My for loop is not working and I'm not sure why. This is the loop: {% for i in range({{text|length}} + {{images|length}}) %} text and images are querysets I have passed to the template from the view. The error I am getting is: django.template.exceptions.TemplateSyntaxError: 'for' statements should use the format 'for x in y': for i in range({{text|length}} + {{images|length}}) This doesn't make sense to me, as it looks to me as if this does follow the format suggested by the error. 回答1: {%

How to set up yaml references within a single .yaml file?

末鹿安然 提交于 2019-12-13 18:57:30
问题 I have inherited a large number of .yaml files that contain an attribute like this: our_price: Our price is just <sup>$</sup><span class="amount">99.95</span> this month Now, the client wants to be able to take our_price, add some taxes and fees, and display a total price in the jinja templates. What I'd like to do is add a new attribute, so it looks like this: simple_price: 99.95 our_price: Our price is just <sup>$</sup><span class="amount">simple_price</span> this month I've tried using

Raspberry Pi - Flask Server using JQuery not working Offline (Online it works)

前提是你 提交于 2019-12-13 17:17:04
问题 I'm a beginner and I have what should be an easy problem to solve. However, after researching many forums and trying the technical solution, I could not make the code to work offline, but it does work just fine loading JQuery online. Let me start explaining my work so far. I used Flask to create an application so I could manipulate an inspection robot using smartphone app or navigator (Raspberry local host). I wrote 2 codes, the Python server and HTML client. It works just fine online,

Python Jinja2 call to macro results in (undesirable) newline

依然范特西╮ 提交于 2019-12-13 16:12:54
问题 My JINJA2 template is like below. {% macro print_if_john(name) -%} {% if name == 'John' -%} Hi John {%- endif %} {%- endmacro %} Hello World! {{print_if_john('Foo')}} {{print_if_john('Foo2')}} {{print_if_john('John')}} The resulting output is Hello•World! Hi•John I don't want the 2 newlines between 'Hello World!' and 'Hi John'. It looks like when a call to macro results in no output from macro, JINJA is inserting a newline anyways.. Is there any way to avoid this? I've put minus in the call

How do I provide a blog excerpt without having to show html code using Jinja2 Template?

╄→尐↘猪︶ㄣ 提交于 2019-12-13 15:01:59
问题 Currently I'm using jinja2 with flask and have stored a blog post using ckeditor in the database. The data should ideally show an image first and then following the blog posts and some other images which are linked externally to flikr. I know that I can use the {{ post.body | safe}} inside the single post view of to display the html as a real image instead of html text. However, how do I NOT show the html but show only the text excerpt in the post in the page where there are multiple links to

Ansible jinja2 filters '|'(pipe) what does it mean?

 ̄綄美尐妖づ 提交于 2019-12-13 12:55:54
问题 I have written a task as below but can not understand what '|' does? tasks: - shell: /usr/bin/foo register: result ignore_errors: True - debug: msg="it failed" when: result|failed - debug: msg="it changed" when: result|changed Also I have found some examples on web but can not understand what '|' does? debug: msg={{ ipaddr |replace(",", ".") }} One more example: - hosts: localhost vars: D: 1 : "one" 2 : "two" tasks: - debug: var=D - debug: msg="D[1] is {{ D[1]|default ('undefined') }}" Would

How to load external javascript in sphinx-doc

我的未来我决定 提交于 2019-12-13 12:21:39
问题 I'm extending the basic theme from sphinx-doc and I notice the following code chunk inside basic theme layout.html script macro {%- for scriptfile in script_files %} <script type="text/javascript" src="{{ pathto(scriptfile, 1) }}"></script> {%- endfor %} Does that mean I can add a html_theme_options like the following inside my theme.conf : [options] script_files = and inside my conf.py , I add: html_theme_options = {'script_files': '_static'} However, with this set, the build is totally

How do I iterate zip list in jinja2 using for loop and display values in HTML table?

可紊 提交于 2019-12-13 09:54:21
问题 I was trying to iterate zip list in jinja2 and display values in HTML table but failed at every single try with a blank page, however, I can display values in the Unordered list like as follows. <ul> {% for bus, info in jnjbus_info %} <li>{{bus}}</li> <li>{{info}}</li> {% endfor %} </ul> This is my flask/function where I passing values to template: @app.route('/busses') def busses(): bus_type = ['AC', 'NON-AC', 'Sleeper', 'NON-Sleeper'] bus_info = ['1010', '2020', '3030', '4040'] return