mydate.strftime('%x') and cgi script

S

Sibylle Koczian

Hello,

I'm writing a cgi script which only needs to run in a small LAN. I tried
to show dates in a reasonable format by using

import locale
import datetime

locale.setlocale(locale.LC_ALL, '')
....
dt = datetime.date.today()
print dt.strftime('%x')

This works well in other scripts or at the interactive prompt. It
doesn't work in a cgi script: in the browser the date is shown as
'mm/dd/yyyy' which is _not_ my 'Locale's appropriate date
representation' as the documentation for strftime calls it.

The workaround is simple: explicit description of the right format works
('%d.%m.%Y'). But why doesn't the short form work as well?

Thank you for explanations or links to them,
Koczian
 
M

Marc 'BlackJack' Rintsch

I'm writing a cgi script which only needs to run in a small LAN. I tried
to show dates in a reasonable format by using

import locale
import datetime

locale.setlocale(locale.LC_ALL, '')
...
dt = datetime.date.today()
print dt.strftime('%x')

This works well in other scripts or at the interactive prompt. It
doesn't work in a cgi script: in the browser the date is shown as
'mm/dd/yyyy' which is _not_ my 'Locale's appropriate date
representation' as the documentation for strftime calls it.

That's the web server's locale appropriate date representation then.

Ciao,
Marc 'BlackJack' Rintsch
 
S

Sibylle Koczian

Marc said:
That's the web server's locale appropriate date representation then.

The web server is on my machine - doesn't it use its regional settings?
I've seen a little more in the meantime:

xx = locale.setlocale(locale.LC_ALL, '')

# print HTML header, title, everything up to and including body tag

print xx

# print rest of page

In the cgi script xx is "C" and not "de_DE.utf-8". Looks as if setlocale
isn't executed.

If I do the same things using Windows instead of Linux, setlocale is
executed in the cgi script, no difference to the interactive interpreter.

Koczian
 
M

Marc 'BlackJack' Rintsch

The web server is on my machine - doesn't it use its regional settings?

The settings are per user and stored in environment variables. Apache
clears most of them at start.
I've seen a little more in the meantime:

xx = locale.setlocale(locale.LC_ALL, '')

# print HTML header, title, everything up to and including body tag

print xx

# print rest of page

In the cgi script xx is "C" and not "de_DE.utf-8". Looks as if setlocale
isn't executed.

`setlocale()` is executed but if there are no environment variables (LANG,
LC_*) then the default locale `C` is chosen.

Ciao,
Marc 'BlackJack' Rintsch
 
S

Sibylle Koczian

Marc said:
The settings are per user and stored in environment variables. Apache
clears most of them at start.



`setlocale()` is executed but if there are no environment variables (LANG,
LC_*) then the default locale `C` is chosen.

And these environment variables aren't there because Apache has cleared
them at start - right?

Thank you,
Koczian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,069
Latest member
SimplyleanKetoReviews

Latest Threads

Top