jinja2

Raising an error in WTForm using jinja2

时光毁灭记忆、已成空白 提交于 2019-12-24 10:12:19
问题 I'm trying to raise an error in Jinja2, in a WTForm, the error should be raised if url input is not validated, but when i submit an invalide url, i get a popup saying "Please enter a url". how do i pass the default popup and add a custom error message ? here is the main py: from datetime import datetime from flask import Flask, render_template, url_for, request, redirect,flash from logging import DEBUG from flask_wtf import FlaskForm from wtforms import StringField, PasswordField from flask

Why does image height get so large in this example?

霸气de小男生 提交于 2019-12-24 09:39:53
问题 I'm calculating image height serverside to serve dynamic images but every once in a while the height in HTML becomes way too large: <div class="item_image" style="height: 1116px"> Why is it so much as 1116px when the pics that a server with get_serving_url actually are not 1116px so I'm probably making some mistake in my algorithm: class NewAdHandler(BaseHandler): def get_ad(self, key): data = memcache.get(key) if data is not None: return data else: data = Ad.get_by_id(long(key)) memcache.add

filter a list of objects with ipaddr in Ansible

夙愿已清 提交于 2019-12-24 08:59:27
问题 If I had a list of ip addresses in Ansible, I could use the ipaddr filter to it and only get the passing values back: - debug: msg: "{{ ['127.0.0.1', 'foo', '2001:db8:32c:faad::'] | ipaddr('address') }}" Unfortunately I am working with a list of objects ( hostvars of group members to be precise). I want to do some tests on the list and only keeping the entries passing - but as objects. When reading the Jinja docs I stumbled across selectattr . Unfortunately it seems that ipaddr isn't a test,

How to get QuerySelectField current value with Flask WTF

て烟熏妆下的殇ゞ 提交于 2019-12-24 08:07:01
问题 If using SelectField we can get the current value that prepopulate in form from database using the obj argument, like this answer on my previous question. For now, I want to get the current value using QuerySelectField . Here is the snippet of my code: def course_list(): return Course.query.all() class PaymentForm(Form): total_price = IntegerField(validators=[required()]) course_name = QuerySelectField('Course name', validators=[required()], query_factory=course_list) # .... # .... And here

Unable to login to the admin panel in Django

冷暖自知 提交于 2019-12-24 07:07:00
问题 The site is working fine but when I switch to http://127.0.0.1:8000/admin/ it shows AttributeError at /admin/ .I tried to include MIDDLEWARE_CLASSES in the mysite/settings.py but to no avail . Here are some details : Django mysite.settings INSTALLED_APPS = [ 'personal', 'blog', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', ] MIDDLEWARE_CLASSES = [ 'django.contrib.sessions

Trimming blocks using whitespace control from jinja2 template

北城余情 提交于 2019-12-24 02:12:14
问题 I'm trying to print a single blank line surrounding the results of a jinja2 for loop, but I just can't get it to work. Can someone tell me what I am doing wrong? from jinja2 import Template, Environment template = Template("""This is some text that should have a single blank line below it. {% for i in range(10) -%} line {{ i }} {% endfor %} This is some text that should have a single blank line above it.""") template.environment = Environment(trim_blocks=True) print(template.render()) This is

Inline CSS background:url() not working in Jinja2 template

假如想象 提交于 2019-12-24 01:47:17
问题 I'm having problem making the Bootstrap Carousel responsive and scaling height and width of dynamic images. One work around I found was to use: background: url(path_to_image.jpg) no-repeat center center; which seems to work okay. Now, I'm trying to factor the code into a Flask/Jinja application: #hp { height: 250px; width: 100%; background-color: gray; /* background: url(https://ununsplash.imgix.net/photo-1427348693976-99e4aca06bb9) no-repeat center center; */ background-size: cover; } <div

AnsibleError: template error while templating string: expected token 'end of statement block', got '{'

丶灬走出姿态 提交于 2019-12-24 00:42:54
问题 Getting AnsibleError: template error while templating string: expected token 'end of statement block', got '{' Here is my jinja2 template, can someone help me figure out what is wrong? no service pad service tcp-keepalives-in service tcp-keepalives-out service timestamps debug datetime msec localtime show-timezone service timestamps log datetime msec localtime show-timezone service password-encryption ! hostname {{item.hostname}} ! boot-start-marker boot-end-marker ! logging buffered 32000 no

how to navigate from one html to other in tornado using anchor tag

北城以北 提交于 2019-12-23 23:29:27
问题 Hi all here is a small application in tornado can any off u please tell me how to navigate from one html to other P.S Now i am getting a error 404 not found should i be using appengine or any other thing is required thanks in advance enter code here import tornado.httpserver import tornado.ioloop import tornado.options import tornado.web from tornado.options import define, options define("port", default=8888, help="run on the given port", type=int) class MainHandler(tornado.web.RequestHandler

Flask|Jinjia2|Javascript: Passing Flask template variable into Javascript

我是研究僧i 提交于 2019-12-23 23:12:10
问题 What is the best way to pass a variable from a Flask template into the Javascript file? Here is my code I have a simple view in my webapp: @webapp.route('/bars') def plot_d3_bars(): return render_template("bars.html", calendarMap = calendarMap) I have a templated HTML file that looks like this: {% extends "base.html" %} {% block title %} Bar View {% endblock %} {% block content %} {% with calendarMap=calendarMap %} {% include "buttons.html" %} {% endwith %} <script src="http://d3js.org/d3.v3