Django での 'Content-Type' の設定について

474 views
Skip to first unread message

tiger

unread,
May 15, 2009, 5:16:28 AM5/15/09
to Google-App-Engine-Japan
はじめまして、タイガーと申します。

php で言うところの header('Content-type: application/xml'); を設定したいのですが、

App Engine + Django(python) ではどのように設定すればよいのでしょうか。

よろしくお願いします。

yagizo

unread,
May 15, 2009, 6:10:43 AM5/15/09
to Google-App-Engine-Japan
はじめまして、やぎぞと申します。

↓このあたりをご覧になるとよろしいのではないでしょうか。
http://code.google.com/intl/ja/appengine/docs/gettingstarted/usingwebapp.html

tiger

unread,
May 15, 2009, 7:30:22 AM5/15/09
to Google-App-Engine-Japan
やぎぞさんありがとう御座います。タイガーです。

↓このあたり
http://code.google.com/intl/ja/appengine/docs/gettingstarted/usingwebapp.html
を見たのですが理解できませんでした、
恐れ入ります。具体的にお願いいたします。

xml作成のメソッドはDjangoのテンプレート機能を使い下記のように記述しています。

def clublistxml(request):
try:
clubs = models.Club.all().order('-created')
except models.Club.DoseNotExist:
data = dict(status=9, msg='Error')
return render_to_response('ClubListXml.xml', data)
#raise Http404

data = dict(status=1, msg='Success', clubs = clubs)
return render_to_response('ClubListXml.xml', data)

上のソースを修正して頂けると助かります。

よろしくお願いします。

keita imaeda

unread,
May 15, 2009, 7:49:57 AM5/15/09
to google-app-...@googlegroups.com
タイガーさん、
はじめまして。chkfjです。

GAE上でうまくいくのか私も自信があまりないのですが、
render_to_responseにはmimetypeというオプションがあると思うので、それを使うとよいかもしれません。

return render_to_response('ClubListXml.xml', data, mimetype="application/xml")

という感じでどうでしょうか。


2009/05/15 20:30 tiger <ytak...@gmail.com>:

tiger

unread,
May 15, 2009, 8:28:26 AM5/15/09
to Google-App-Engine-Japan
chkfjさん、ありがとうございます。
タイガーです。

return render_to_response('ClubListXml.xml', data,
mimetype="application/xml")

実行しましたがうまくいきませんでした。

開発には Eclipse を使用していますが Console には、
INFO 2009-05-15 21:13:16,069 dev_appserver.py] "GET /clublistxml/
HTTP/1.1" 500 -

アクセスしたブラウザ(Firefox)には、
TypeError at /clublistxml/
render_to_string() got an unexpected keyword argument 'mimetype'

Request Method: GET
Request URL: http://localhost:8080/clublistxml/
Exception Type: TypeError
Exception Value: render_to_string() got an unexpected keyword
argument 'mimetype'
Exception Location: C:\Program Files\Google\google_appengine\lib
\django\django\shortcuts\__init__.py in render_to_response, line 10

と表示されます。

1.GAEで何か設定が有るのでしょうか?
2.GAEのDjangoはversion 0.96ですが関係ありますか?

ほかに方法がありましたらよろしくお願いいたします。

Takashi Matsuo

unread,
May 15, 2009, 8:57:44 AM5/15/09
to google-app-...@googlegroups.com
松尾です。

2009/5/15 tiger <ytak...@gmail.com>:


>
> chkfjさん、ありがとうございます。
> タイガーです。
>
> return render_to_response('ClubListXml.xml', data,
> mimetype="application/xml")

res = render_to_response('ClubListXml.xml', data)
res['Content-Type'] = 'application/xml'
return res

こんな感じでいけませんかね。

Happy coding :-)

-- Takashi Matsuo

tiger

unread,
May 15, 2009, 9:59:01 AM5/15/09
to Google-App-Engine-Japan
松尾さん、ありがとうございます。
タイガーです。

いけました。助かりました。

I'm Happy ! Thank You... by tiger
Reply all
Reply to author
Forward
0 new messages