我有一个适用于Django的应用程序。一个简单的数字转换器,从罗马到小数,反之亦然。我自己做了对流器,使其成为一个模块。我无法发出Ajax请求,因此一切都没有更新。
viewes.py
from . import decroman
def home(request):
data = {
'title': 'Convector',
}
return render(request, 'convector/convector.html', data)
def res(request):
if request.method == "GET":
if 'InputConvert' in request.GET:
num = decroman.decroman(request.GET['InputConvert'])
result = num.result
data = {
'convert': request.GET['InputConvert'],
'result': result,
'title': 'Result',
}
return HttpResponse(result)
# return render(request, 'convector/result.html', data)
else:
return HttpResponseRedirect('/')
def res(request):
if request.method == "GET":
if 'InputConvert' in request.GET:
num = decroman.decroman(request.GET['InputConvert'])
result = num.result
data = {
'convert': request.GET['InputConvert'],
'result': result,
'title': 'Result',
}
return HttpResponse(result)
# return render(request, 'convector/result.html', data)
else:
return HttpResponseRedirect('/')
一开始的本质是,当您开始时,将显示home方法。填充并发送到HTML后,将重定向到包含答案的页面。
convector.html
<form action="/result/" method="get" class="form-group">
<div class="form-row">
<div class="form-group col-md-5">
<div class="form-group">
<label for="InputConvert">Enter numbers</label>
<textarea class="form-control" id="InputConvert" rows="10" required name="InputConvert"></textarea>
</div>
</div>
<button type="submit" class="btn btn-primary">Converting</button>
<div class="form-group col-md-5">
<label for="OutputConvert">Convert</label>
<textarea class="form-control" readonly id="StaticResult" rows="10"></textarea>
</div>
</div>
</form>
如何在Ajax的帮助下完成?