1
Django-templates에서 Ajax를 사용하는 방법은 무엇입니까?Django-templates에서 Ajax를 사용하는 방법?
urls.py
from django.conf.urls import patterns, url
urlpatterns = patterns('',
url(r'^home/$', 'views.index'),)
views.py
from django.template import RequestContext
from django.shortcuts import render_to_response
def index(request):
val = request.POST.get('val', default='text_text')
return render_to_response(
'index.html',
{'text': val,},
context_instance=RequestContext(request))
index.html을
<p>text and pictures</p>
<p>text and pictures</p>
<h1>{{ text }}</h1>
<form action="/home/" method="post">
{% csrf_token %}
<input type="text" name="val" id="val" value="{{ val }}"/> <br/>
<input type="submit" value="OK" />
</form>
<p>text and pictures</p>
<p>text and pictures</p>
어떻게하면이 OK 버튼을 누를 때 그렇게 할 수 있습니까? 은 태그 h1 사이에 페이지의 일부만 업데이트합니다.
[? 장고에 가장 AJAX 라이브러리 란 (http://stackoverflow.com/ 질문/511843/what-is-the-the-best-ajax-django 라이브러리) –
간단한 아약스 호출에 대한이 링크를 읽을 수 있습니다 http://stackoverflow.com/questions/21259988/dj ango-ajax-httpresponse-json-error-unexpected-token-d/21260734 # 21260734 –