0

What's the easiest way to pass a text that contains spaces from python backend to a view in html?

When I try to pass the following via a returned variable in html in web2py, I only get the first word before the first space.

text = "bla bla"

in html inside an input:

<input value={{=text}} />

result is:

bla

Yes, this issue does not exist if {{=text}} used outside input.

3
  • There is no problem inserting text with spaces, and even your example code will in fact render "bla bla". Probably there is something else going on in your real code that is causing the issue. Please show the real code that exhibits the problem, and it might also help to show the final rendered HTML (i.e., what you see via "view source" or by looking at the network response in the browser developer tools). Commented Sep 2, 2019 at 17:58
  • when the {{=text}} is used in an input such as <input value={{=text}}>, then the text cuts off right before a space in the text. But, you are right in a normal html there is no problem. I realized I do not need an input anyways and used {{=text}} in the html. However, if you know the root cause, it would be great to know. Commented Sep 10, 2019 at 22:25
  • Yes, as noted, that is not a problem with web2py, which will insert the text in the source exactly as specified. Commented Sep 11, 2019 at 2:37

1 Answer 1

1

The value attribute of an input element must be in quotes:

<input value="{{=text}}" />

Without the quotes, web2py will generate the following HTML:

<input value=bla bla />

The browser will interpret that as value=bla along with another (invalid) attribute named bla.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.