jinja2

iPython notebook on Mac OSX Yosemite: no module named jinja2, even if it's installed

时光总嘲笑我的痴心妄想 提交于 2020-01-23 11:49:36
问题 I am trying to run iPython notebook on OSX Yosemite. I have installed everything via pip install ipython[all] and I see mattia:~ mattiaspeziali$ pip freeze backports.ssl-match-hostname==3.4.0.2 certifi==14.5.14 docutils==0.12 gnureadline==6.3.3 ipython==2.3.1 Jinja2==2.7.3 MarkupSafe==0.23 nose==1.3.4 numpy==1.8.2 numpydoc==0.5 pandas==0.14.1 Pygments==2.0.1 pyzmq==14.4.1 Sphinx==1.2.3 tornado==4.0.2 vboxapi==1.0 However, jinja2 seems not installed properly: mattia:~ mattiaspeziali$ ipython

How do I return a list as a variable in Python and use in Jinja2?

浪尽此生 提交于 2020-01-22 09:29:05
问题 I am a very young programmer and I am trying to do something in Python but I'm stuck. I have a list of users in Couchdb (using python couchdb library & Flask framework) who have a username (which is the _id) and email. I want to use the list of email addresses in a select box in a jinja2 template. My first problem is how to access the email addresses. If I do: for user in db: doc = db[user] emails = doc['email'] print options I get: email@domain.com otheremail@otherdomain.com yetanotheremail

How to set javascript value to jinja variable

人盡茶涼 提交于 2020-01-21 11:54:26
问题 I know we can set Jinja variable to js variable like this. var x = {{ 'value' }} but I am trying to do the reverse. i.e I am trying to set javascript value to jinja variable. I tried the following but nothing worked. {{value}} = x {% set value = x %} {% set value %} x {% endset %} x is javascript variable. is there any way to achieve this. 回答1: This is not possible, and reflects a deep problem in your understanding of the web application architecture. jinja2 is a templating engine for Python,

在Jinja2模板中使用复杂数据

独自空忆成欢 提交于 2020-01-19 16:20:22
在Jinja2模板中传递列表、字典、对象 在模板文件中,要引用内部变量的值。如传递一个列表mylist,需在模板文件中使用mylist[0],mylist[1]引用列表中的元素。传递一个字典,需在模板文件中使用mydict[‘key’]引用key对应的value 实例:向模板文件template.txt(template.html)传递4种复杂类型的数据,并在模板文件中输出这些复杂类型数据中相应的值 template.txt 此处使用txt和html格式的文件均可,数据形式一样 < !DOCTYPE html > < html lang = "en" > < head > < meta charset = "UTF-8" > < title > Jinja2模板测试 < / title > < / head > < body > < h1 > 字典 : { { mydict [ 'type' ] } } < / h1 > < h1 > 列表 : { { mylist [ 0 ] } } < / h1 > < h1 > 函数 : { { myfunc ( ) } } < / h1 > < h1 > 对象 : { { myclass . func ( ) } } < / h1 > < / body > < / html > template_Jinja2.py from flask

Flask-Images does not work

≡放荡痞女 提交于 2020-01-17 02:17:29
问题 I'm installed Flask-images for resizing some images. My code are like this: <img src = '{{url_for('showimages', filename = market.thumbnail, width=100, height=100, mode='crop')}}'> showimages : @app.route('/image/user/<filename>') def showthumbnail(filename): return send_from_directory(app.config['UPLOAD_FOLDER'], filename) There are nothing happens and my Chrome devaloper tools said image's url like this: <img src="/image/user/Untitled-1.png?width=100&height=100&mode=crop"> I know there is

Querying multiple tables in Flask using sqlite3

我的梦境 提交于 2020-01-16 16:01:32
问题 Can anyone please give me a simpler solution for this? I'm trying to query four different tables in my database and iterating them with a very bizarre FOR pattern, within HTML. All the time I get MemoryError because the database is huge. Python script: import sqlite3 con=sqlite3.connect('/home/sergiuster/Downloads/python/exportSQL.db', check_same_thread=False) con.row_factory = sqlite3.Row #QUERY MATERIALECARACT cur = con.cursor() cur.execute("SELECT MaterialeCaracteristici.CodProdus,

Querying multiple tables in Flask using sqlite3

心已入冬 提交于 2020-01-16 16:01:12
问题 Can anyone please give me a simpler solution for this? I'm trying to query four different tables in my database and iterating them with a very bizarre FOR pattern, within HTML. All the time I get MemoryError because the database is huge. Python script: import sqlite3 con=sqlite3.connect('/home/sergiuster/Downloads/python/exportSQL.db', check_same_thread=False) con.row_factory = sqlite3.Row #QUERY MATERIALECARACT cur = con.cursor() cur.execute("SELECT MaterialeCaracteristici.CodProdus,

Access values from a dict in a function called in a Jinja expression

╄→尐↘猪︶ㄣ 提交于 2020-01-15 20:17:18
问题 I'm passing a dict from a Flask view to a Jinja template. I can render the values in the dict, but if I try to pass them to url_for I get UndefinedError: 'dict object' has no attribute 'eId' . Why did the second access fail when the first succeeded? @app.route('/') def show_entries(): if session.get('logged_in'): cur = g.db.execute('select title, text, id from entries1 WHERE userid = ? OR public = 1 order by id desc', [userInfo['userid']]) else: cur = g.db.execute('select title, text, id from

Python UnicodeDecodeError: 'utf8' codec can't decode byte… unexpected code byte

若如初见. 提交于 2020-01-15 18:52:26
问题 Python newbie's journey to build his first webapp (app link: http://contractpy.appspot.com/ - it's just an experimental app). Following an advice of a stackoverflow user, I start to use a template system: Jinja2 (I'm using Python 2.6), but now I'm stucked with this error: 2012-06-17 11:44:39 Running command: "['C:\\Python26\\pythonw.exe', 'C:\\Program Files (x86)\\Google\\google_appengine\\dev_appserver.py', '--admin_console_server=', '--port=8084', 'C:\\Users\\CG\\Documents\\udacity\

Python UnicodeDecodeError: 'utf8' codec can't decode byte… unexpected code byte

天涯浪子 提交于 2020-01-15 18:52:17
问题 Python newbie's journey to build his first webapp (app link: http://contractpy.appspot.com/ - it's just an experimental app). Following an advice of a stackoverflow user, I start to use a template system: Jinja2 (I'm using Python 2.6), but now I'm stucked with this error: 2012-06-17 11:44:39 Running command: "['C:\\Python26\\pythonw.exe', 'C:\\Program Files (x86)\\Google\\google_appengine\\dev_appserver.py', '--admin_console_server=', '--port=8084', 'C:\\Users\\CG\\Documents\\udacity\