티스토리 뷰

Python 파일에서 한글을 쓰기 위해서는 

# -*- coding: utf-8 -*-

를 맨 위에 적어 놓는다.

---------------

링크나 첨부파일에 

string 변수 .encode('utf-8')

으로  utf-8로 인코딩 해준다. 


query = urllib.quote(title.encode('utf-8')+" "+name.encode('utf-8'))
url = "http://music.naver.com/search/search.nhn?query="+query

---------------

파일 다운로드시 

sock = open(music.PATH, 'r')
response = HttpResponse(sock, content_type="application/force-download")
response['Content-Disposition'] = 'attachment; filename*=UTF-8\'\'%s' %

urllib.quote(music.FILE_NAME.encode('utf-8'))

return response

이런식으로 사용하면 된다.

urllib.quote() : 

quote('abc def') -> 'abc%20def'

Each part of a URL, e.g. the path info, the query, etc., has a
different set of reserved characters that must be quoted.

RFC 2396 Uniform Resource Identifiers (URI): Generic Syntax lists
the following reserved characters.

reserved    = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" |
              "$" | ","

Each of these characters is reserved in some component of a URL,
but not necessarily in all of them.

By default, the quote function is intended for quoting the path
section of a URL.  Thus, it will not encode '/'.  This character
is reserved, but in typical usage the quote function is being
called on a path where the existing slash characters are used as
reserved characters.


댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
글 보관함