< 3 AJAX & 장고! 아주 재미. Dajax은 아약스로 작업하기가 쉽습니다 (시작하기가 쉽지만).
import json
from django.http import HttpResponse
from django.template import Template, Context
def ajax(request):
"""returns json response"""
return HttpResponse(json.dumps({'foo': 'bar'}), mimetype='application/json')
def index(request):
"""simple index page which uses jquery to make a single get request to /ajax, alerting the value of foo"""
t = Template("""
<!doctype html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script type="text/javascript">
$.get('/ajax/', function(data) {
alert(data['foo']);
});
</script>
</head>
</html>""")
return HttpResponse(t.render(Context()))
# urlconf
urlpatterns = patterns('',
(r'^$', index),
(r'^ajax/', ajax),
)
: 여기 당신이 (urls.py에서 사용)을 재생할 수있는 간단한 예입니다,
그리고 다음은 몇 가지 더 블로그 게시물이 모든 답장을 보내 주셔서 감사합니다. 나는 그 (것)들을 통해가는 과정에 있고 그 때 받아들이는 누구 응답을 결정할 것이다. :) – tamakisquare
답변을 선택하십시오. – Unapiedra