'app engine python 한글처리'에 해당되는 글 1건

  1. 2012.11.07 appengine templete 렌더링시 한글오류 처리
WEB
posted by 구름너머 2012. 11. 7. 11:59

한글 인코딩 관련 참고 블로그 : http://pak2536.tistory.com/35

 

오류 : UnicodeDecodeError: 'ascii' codec can't decode byte 0xc7 in position 0: ordinal not in range(128)

구글 appengine에서 템플릿파일에 대한 렌더링시 한글처리가 잘 안되어서 아래방법으로 성공했습니다.

환경: 윈도우즈7-Chrome

파이썬2.7, 구글웹엔진

1.윈도우즈용 파이썬 설치하기 ==> 2.7
  http://www.python.org/download/
  ==> Python 2.7.3 Windows Installer (Windows binary -- does not include source)

2.윈도우즈용 구글앱엔진 설치하기 ==>
  https://developers.google.com/appengine/downloads

 

1. .py파일을 고친다.

#!/usr/bin/python
# -*- coding: cp949 -*-

.....

    test_str='한글(HANGUL) UTF-8 or CP949 테스트(TEST) 입니다.'
    test_str=unicode(test_str,'cp949')
 
    logging.info('test_str========================>' + test_str)
    logging.info('UNICODE:'+test_str.encode('utf-8'))
    template_values = {'token': token,
                       'me': user,
                       'room_key': room_key,
                       'room_link': room_link,
                       'initiator': initiator,
                       'pc_config': json.dumps(pc_config),
                       'test_str': test_str 
                      }

template = jinja_environment.get_template('templetes/index.html')

self.response.out.write(template.render(template_values))

2. 템플릿의 html파일에서...

<h2><a href="#">Video&nbsp;&nbsp;&nbsp;Guide  Ha {{ test_str }} </a></h2>

 

다른방법이 있으면 좋을텐데 아직 못찾음...ㅠㅠ

==> 다른 방법이 있네요.

     에디터 프로그램에서 HTML파일을 다른이름으로 저장하기에서 서식을 UTF-8 포맷으로 저장하면 한글이 인식되네요.

 

 

한글처리 예.xlsx

 

'WEB' 카테고리의 다른 글

WebLogic SSL 설정  (0) 2012.11.13
HTML5 변경 및 Validator를 이용한 검사  (0) 2012.11.09
google appengine 으로 app 만들고 올리기  (0) 2012.10.19
centOS6.3 설치 외  (0) 2012.10.16
webRTC Demo  (0) 2012.10.15