【发布时间】:2016-09-01 07:47:26
【问题描述】:
这是我的 View.py 代码...
import requests
from django.http import HttpResponse
from django.shortcuts import render import json
def book(request):
if request.method == 'POST':
r = requests.post('http://api.railwayapi.com/cancelled/date/01-09-2016/apikey/mezxa1595/', params=request.POST)
book=r.json()
else:
r = requests.get('http://api.railwayapi.com/cancelled/date/01-09-2016/apikey/mezxa1595/', params=request.GET)
book=r.json()
js=json.dumps(book)
if r.status_code == 200:
return render(request,'book.html', {'js':js})
return HttpResponse('Could not save data')
问题是如何在 Html 中显示return render(request,'book.html', {'js':js})?
【问题讨论】:
-
能否修复代码格式以提高可读性?
-
你要写book.html文件。
-
跟着 django-tutorial 你会发现的。
标签: javascript python json django