Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8829405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:49:41+00:00 2026-06-14T07:49:41+00:00

I am using Flask, WTForms and Backbone.js to create my app. I am working

  • 0

I am using Flask, WTForms and Backbone.js to create my app. I am working with Backbonejs for first time.

I have created a Backbone js template to display data and its corresponding form.

    <%= my_field1 %>
    <%= my_field2 %>
    <form>
        <input type="text" value="<%= my_field1 %>"/>
        <input type="text" value="<%= my_field2 %>"/>
    </form>

I am using WTForms and Jinja2 to render my form. To give initial value I am doing this

    {{ field1(value="<%= my_field1 %>") | safe }}
    {{ field1(value="<%= my_field1 %>") | safe }}

This is a source of problem as <% is escaped while rendering. How can I stop wtforms/jinja from escaping this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T07:49:42+00:00Added an answer on June 14, 2026 at 7:49 am

    I looked at WTForms’ source code, and yeah, it escapes HTML characters as part of rendering, which you’re doing by calling the field. So the jinja “safe” parameter is acting too late.

    You can get around this by creating a custom widget to render your field:

    http://wtforms.simplecodes.com/docs/0.6/widgets.html#custom-widgets

    I took a crack at writing a widget for you – I apologize that I haven’t run this code, but it should be enough to get you going in the right direction.

    If you run into trouble, be sure to check out WTForms’ source code: it’s well-commented, there’s not a lot of it, and you can crib from there. (I did!)

    from wtforms.widgets.core import HTMLString 
    
    # Custom widget display 
    def input_field_with_unescaped_value(field, **kwargs):
    
      value = kwargs.pop('value', field._value())
      unescaped_output = u' value="%s"' % value if value else ''
    
      return HTMLString(u'<input %s%s>%s</input>' % \
          (html_params(name=field.name, **kwargs), \
          unescaped_output, \
          unicode(field._value()))
    
    # and here's how you use it in a form
    class MyForm(Form):
      field1 = TextField(u'Thingy', widget=input_field_with_unescaped_value)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently working on a project using Flask and Google App Engine . Calling
I am using Flask, WTForms, and the OurSQL MySQL library for my app. I
I'm using Flask in an app that render some data from a sqlite database.
I have been using Flask for some time now and I am really enjoying
I'm using flask-sqlalchemy to build a webapp and I have the following model(s): class
I'm using flask with a jinja2 template which includes another jinja2 template called buttons.html.
I am using Flask/Jinja2 template to show a number using |float filter. Here is
I'm developing a fairly straightforward web app using Flask and MySQL. I'm struggling with
When using Google App Engine 1.6.4 testbed with Flask 0.8, and in particular the
I am writing my website's backend using Flask and Python 2.7, and have run

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.