I would like to use datetime.strftime in the SimpleTemplate of Bottle to match the value in the form to the pattern specified in the pattern attribute
If strftime is executed, the value of format_now
should match the pattern of the form.
However, if you actually access it with a browser, you will only see the Western calendar and date as shown in Figure 1
Why is that?
import datetime
import bottle
jst=datetime.timezone(datetime.timedelta(hours=9), "JST")
@bottle.route("/")
def index():
now=datetime.datetime.now(jst)
return bottle.template("template.tpl", {"now":now})
template.tpl:
%format_now=now.strftime("%Y-%m-%d%I:%M:%S%p")
<input type="text" pattern="\d{4}-\d{1,2}-\d{1,2}-\d{1,2}(1[0-2]|0[0-9]:[0-5][0-9]:[0-5][0-9](PM|AM)?" name="now"value={{format_now}}}}>
value
attribute value is not quoted.
As you can see by displaying the HTML source after generation,
<input type="text"...value=2016-08-08 11:14:20 PM>
Because of the , only the first space is considered a value of value
and only the date and time are displayed.
value="{{format_now}}"
(enclosed in quotation).
572 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
578 Understanding How to Configure Google API Key
574 Who developed the "avformat-59.dll" that comes with FFmpeg?
581 PHP ssh2_scp_send fails to send files as intended
915 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
© 2024 OneMinuteCode. All rights reserved.