flask-wtforms

Embed HTML tag in Flask WTForms field

夙愿已清 提交于 2019-12-11 04:42:38
问题 I'm using Flask with Jinja2/WTForms to build a login page and I want to customize a "Remember Me" checkbox. To do this, I would like to embed an empty <span> tag into the form's label field. Here is the Jinja2 code in the HTML file: {{ login_user_form.remember|safe }} {{ login_user_form.remember.label }} which generates the following HTML: <input id="remember" name="remember" type="checkbox" value="y"> <label for="remember">Remember Me</label> However, the following HTML is what I would

No module named flask.ext.wtf.SelectField

╄→гoц情女王★ 提交于 2019-12-11 03:54:06
问题 I found flask-jquery-ajax-example and I tried to run it with the latest library versions: $ pip install flask flask-wtf wtforms $ pip install -e ./ However, I got the ImportError: No module named flask.ext.wtf.SelectField while starting the scripts: $ python bin/runserver.py Traceback (most recent call last): File "bin/runserver.py", line 2, in <module> from fjae import run_dev_server File "/home/mic/tmp/flask-jquery-ajax-example/fjae/__init__.py", line 3, in <module> from fjae import views

Select default value for flask wtforms selectfield within jinja for dynamic data

核能气质少年 提交于 2019-12-10 19:18:49
问题 I'm trying to set the default value for a select field that is dynamically generated using a for loop using jinja within the html page and i cant find a solution to do this in the documentation. Basically i need a way to set the default value of the selectfield using jinja if possible. I cant set the default value from the routes side or the forms side in python because the fields are made dynamically and the default values need to be different depending on the choices. I can set the default

ListField is showing <ul> instead of <input> in edit/create post

隐身守侯 提交于 2019-12-10 18:54:59
问题 I am using Flask, mongoengine for a project and I am trying to get basic stuff working from http://docs.mongodb.org/manual/tutorial/write-a-tumblelog-application-with-flask-mongoengine/ After implementing everything from above link I added a new field for "tags" in Post and when I try to create a post, my tags doesn't show a input box. Any help is appreciated. My code and screenshot below class Post(db.DynamicDocument): created_at = db.DateTimeField(default=datetime.datetime.now, required

Dynamically change WTForms field type between SelectField and HiddenField

半世苍凉 提交于 2019-12-10 18:24:55
问题 I have a WTForms field (value_currency) that I want to sometimes be a SelectField and sometimes a HiddenField. I use the same view and template for a page that both creates new items and edits existing items. If I load the page to create a new item, I want this field to be a SelectField, and if I load the page to edit an existing item, I want this field to be a HiddenField because it's a non-editable field. Here is what I have so far: FORM class PromoForm(Form): value = StringField('value')

Create a custom field in wtForms

会有一股神秘感。 提交于 2019-12-10 13:37:07
问题 In my form I am trying to create a custom array field with choices. The custom form field: class CustomField(Field): widget = TextInput() def _value(self): if self.data: return u', '.join(self.data) else: return u'' def process_formdata(self, valuelist): if valuelist: self.data = [x.strip() for x in valuelist[0].split(',')] else: self.data = [] The actual form calls the custom form field class PostForm(Form): status = CustomField() Whenever, I post data to PostForm it calls the custom field

Flask disable CSRF in unittest

时光怂恿深爱的人放手 提交于 2019-12-10 13:29:20
问题 In my projects __init__.py I have this: app = Flask(__name__) app.config.from_object('config') CsrfProtect(app) db = SQLAlchemy(app) My development config file looks like: import os basedir = os.path.abspath(os.path.dirname(__file__)) DEBUG = True WTF_CSRF_ENABLED = True SECRET_KEY = 'supersecretkey' SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'project.db') SQLALCHEMY_TRACK_MODIFICATIONS = False And in my unittest setUp I have this: from project import app, db class

File not uploading with Flask-wtforms in cookiecutter-flask app

耗尽温柔 提交于 2019-12-10 12:33:17
问题 I am having a problem getting a file upload to work in a cookiecutter-flask app (v. 0.10.1). Right now, it is not saving the file uploaded. Cookiecutter-Flask by default installs WTForms and Flask-WTForms. I have tried adding Flask-Uploads to this but I'm not convinced that module adds anything at this point so I have uninstalled it. This is the Flask-WTF file upload documentation: http://flask-wtf.readthedocs.io/en/latest/form.html#module-flask_wtf.file The main difference between the

Render a Jupyter Notebook Iframe in Flask

南笙酒味 提交于 2019-12-10 11:36:42
问题 I'm using Flask to host a UI for a single user. Something I've been trying to do is setup a way for user to click a button that inserts some text and images in a pre-specified place in a document using markup language. I originally used Jinja2 for this but the issue is the user needs to be able to modify the document after the data is inserted in case they need to make small changes to the text or add a line etc... which to my knowledge can't be done with a flask-rendered template. I

Hiding a form-group with Flask Jinja2 and WTForms

旧城冷巷雨未停 提交于 2019-12-10 10:52:38
问题 I'm trying to show or hide a form field based on the state of a checkbox in another part of the form. I thought that I could do this with jQuery .show() or .hide() with relative ease, but I'm not having much luck so far. Any thoughts? The form class: class MyForm(Form): checked = BooleanField('Check this box:') date = DateField('Date:', format='%Y-%m-%d', id="dates") submit = SubmitField('Submit') The template: {% import "bootstrap/wtf.html" as wtf %} {% block content %} {{ form.hidden_tag()