On Thu, May 8, 2014 at 5:05 AM, Sugita Shinsuke <shinr...@gmail.com> wrote:
> Hello Tom Evans
>
>
>> plain single and double quotes - " and ', not “ and ‘.
> My e-mail client is Gmail web client.
>
>>What version of Python? 2.x or 3.x?
> Python version is 2.7.5
> And, Django version is 1.3.7

Django 1.3.7 is very old, it has known security holes in it and is not
maintained. What I talk about from here on down is not relevant for
1.3 - upgrade to at least 1.6.

In Python 2, you should mark your strings as unicode if they contain
anything other than ascii.

  u'This is a unicode string'

 'This is a byte string'

The characters within the string should be in the encoding specified
for the current file. See:

https://docs.python.org/2/howto/unicode.html#unicode-literals-in-python-source-code

Unicode strings are converted to the correct encoding for your
environment when output (running a command "outputs" the string to the
shell).

So, if you want your management command to output UTF-8:

1) Mark the strings in your program as unicode
2) Mark the files containing unicode string literals to denote the
character encoding used by the string literals
3) Ensure the environment that django is run in has the locale
correctly specified.
4) Ensure your management command either:
  a) Activates a fixed language prior to outputting unicode or
  b) Instructs django to use locale from the environment
  See 
https://docs.djangoproject.com/en/1.6/howto/custom-management-commands/#management-commands-and-locales

Cheers

Tom

>
>>There was an old case to force Django to use UTF-8:
> I added
> sys.stdout = codecs.getwriter('utf-8')(sys.stdout)
> But, I couldn't resolve...
>
>>language that user requests (if supported and USE_i18N=True) or
> LANGUAGE_CODE otherwise.
>
> Both of them are True.
> USE_I18N = True
> USE_L10N = True
>
>
> 2014年5月8日木曜日 1時23分01秒 UTC+9 Tom Evans:
>>
>> On Sun, Apr 27, 2014 at 7:13 AM, Sugita Shinsuke <shin...@gmail.com>
>> wrote:
>> > Hi there
>> >
>> > I’d like to run Java code via Django.
>> >
>> > The Java code, javaprogram use like below.
>> >
>> > —
>> > java javaprogram [text] [file_name]
>> > —
>> >
>> > text is parameter. multi-byte character is also okey.
>> > file_name is generate file name.
>> >
>> > So, I run the stand-alone Python program like below could run fine.
>> > —
>> > java_file = ‘javaprogram’
>> > file_name = ‘filename’
>> > text = ‘あいうえお’ #Japanese character
>> > java_file_path = ‘/path/to/‘
>> > class_path = ‘-cp ' + java_file_path
>> >
>> > cmd = “java {0} {1} {2} {3}".format(class_path, java_file, text,
>> > file_name)
>>
>> What version of Python? 2.x or 3.x?
>>
>> Presumably your email client is converting plain single and double
>> quotes to smart quotes and backticks, and in your source code they are
>> plain single and double quotes - " and ', not “ and ‘.
>>
>> Django does something explicitly to force management commands to be
>> ascii, see here:
>>
>>
>> https://docs.djangoproject.com/en/1.6/howto/custom-management-commands/#management-commands-and-locales
>>
>> There was an old case to force Django to use UTF-8:
>> https://code.djangoproject.com/ticket/5877
>>
>> It was closed wontfix on the basis that Django respects your locale,
>> which it no longer does by default. There are several workarounds
>> listed on the first link that will restore that behaviour. Within a
>> view code, the rules are different, it will activate either the
>> language that user requests (if supported and USE_i18N=True) or
>> LANGUAGE_CODE otherwise.
>>
>> Cheers
>>
>> Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFHbX1LU%2B8CfePtBbcY%3Dg-o_bM8Peri9oazTv6YOW8U6kGBcMw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to