Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #101585 > unrolled thread
| Started by | tdsperth@gmail.com |
|---|---|
| First post | 2016-01-12 17:52 -0800 |
| Last post | 2016-01-13 22:29 +1100 |
| Articles | 5 — 3 participants |
Back to article view | Back to comp.lang.python
Data Entry tdsperth@gmail.com - 2016-01-12 17:52 -0800
Re: Data Entry Chris Angelico <rosuav@gmail.com> - 2016-01-13 13:01 +1100
Re: Data Entry tdsperth@gmail.com - 2016-01-12 18:58 -0800
Re: Data Entry Peter Otten <__peter__@web.de> - 2016-01-13 12:21 +0100
Re: Data Entry Chris Angelico <rosuav@gmail.com> - 2016-01-13 22:29 +1100
| From | tdsperth@gmail.com |
|---|---|
| Date | 2016-01-12 17:52 -0800 |
| Subject | Data Entry |
| Message-ID | <6ea58259-05f8-40b5-8c85-46a69668c8e6@googlegroups.com> |
Hi All
I have written a small web app using cgi for testing for changes to data from a python script that does a lot of database updating depending on certain conditions
form = cgi.FieldStorage()
cRefNo = form.getvalue('refno')
cElectSupp = form.getvalue('electsupp')
print('<font size = 3 color = "black">Electrical Supplier : <input type="text" name="electsupp" value=%s>'%cElectSupp)
If i change the value from origin to origin energy and save - the value updated to the database is correct but when the page is re displayed it only
shows origin in the text field - as if it ignores everything after the space.
How do I make it display the full name.
Cheers
Colin
[toc] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2016-01-13 13:01 +1100 |
| Message-ID | <mailman.88.1452650480.13488.python-list@python.org> |
| In reply to | #101585 |
On Wed, Jan 13, 2016 at 12:52 PM, <tdsperth@gmail.com> wrote: > If i change the value from origin to origin energy and save - the value updated to the database is correct but when the page is re displayed it only > shows origin in the text field - as if it ignores everything after the space. > > How do I make it display the full name. > To set a multi-word value as an HTML attribute, you'll need to put quotes around it. You might be able to get away with using %r instead of %s, or even just "%s", but proper escaping would be the best way. ChrisA
[toc] | [prev] | [next] | [standalone]
| From | tdsperth@gmail.com |
|---|---|
| Date | 2016-01-12 18:58 -0800 |
| Message-ID | <9d3a8c53-ba8b-4ec0-8570-2a523132ebdb@googlegroups.com> |
| In reply to | #101585 |
On Wednesday, January 13, 2016 at 9:52:17 AM UTC+8, tdsp...@gmail.com wrote:
> Hi All
>
> I have written a small web app using cgi for testing for changes to data from a python script that does a lot of database updating depending on certain conditions
>
> form = cgi.FieldStorage()
> cRefNo = form.getvalue('refno')
>
>
> cElectSupp = form.getvalue('electsupp')
>
>
> print('<font size = 3 color = "black">Electrical Supplier : <input type="text" name="electsupp" value=%s>'%cElectSupp)
>
>
> If i change the value from origin to origin energy and save - the value updated to the database is correct but when the page is re displayed it only
> shows origin in the text field - as if it ignores everything after the space.
>
> How do I make it display the full name.
>
> Cheers
>
> Colin
Hi Chris
%r worked a treat
thanks
Colin
[toc] | [prev] | [next] | [standalone]
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Date | 2016-01-13 12:21 +0100 |
| Message-ID | <mailman.97.1452684100.13488.python-list@python.org> |
| In reply to | #101585 |
Chris Angelico wrote:
> On Wed, Jan 13, 2016 at 12:52 PM, <tdsperth@gmail.com> wrote:
>> If i change the value from origin to origin energy and save - the value
>> updated to the database is correct but when the page is re displayed it
>> only shows origin in the text field - as if it ignores everything after
>> the space.
>>
>> How do I make it display the full name.
>>
>
> To set a multi-word value as an HTML attribute, you'll need to put
> quotes around it. You might be able to get away with using %r instead
> of %s, or even just "%s",
That is bad advice that "works" until there is a value containing
quotes or other markup.
> but proper escaping would be the best way.
OP, that's what you should do. Either pick one of the many templating
languages -- a simple one is
http://bottlepy.org/docs/dev/stpl.html
>>> from bottle import SimpleTemplate
>>> SimpleTemplate('... value="{{supplier}}">').render(
... supplier="<foo> 'bar' \"baz\"")
'... value="<foo> 'bar' "baz"">'
-- or at least manually apply html.escape() to the value:
>>> import html
>>> '... value="%s">' % html.escape("<foo> 'bar' \"baz\"")
'... value="<foo> 'bar' "baz"">'
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2016-01-13 22:29 +1100 |
| Message-ID | <mailman.98.1452684579.13488.python-list@python.org> |
| In reply to | #101585 |
On Wed, Jan 13, 2016 at 10:21 PM, Peter Otten <__peter__@web.de> wrote: >> To set a multi-word value as an HTML attribute, you'll need to put >> quotes around it. You might be able to get away with using %r instead >> of %s, or even just "%s", > > That is bad advice that "works" until there is a value containing > quotes or other markup. > Which is why I said "get away with". If you know your data, you might know that it can have spaces but never quotes, for instance. But proper escaping is definitely the way to go. ChrisA
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web