私は自分のPCでdjangoを使ってテストを行っています.ifステートメントが真でr1変数が正しいコードを実行した場合。
def trovapernome(request, aggregatore, nome):
url = urllib.urlopen("http://127.0.0.1:8000/media/%s.xml" % (aggregatore))
richiesta = url.read()
tree = ET.fromstring(richiesta)
iterator = tree.getiterator("location")
t = get_template('prova.xml')
for name in tree.iter('name'):
if name.text.lower() == nome.lower():
c = Context({'id' : name.text})
r1 = HttpResponse(t.render(c), mimetype='application/xml')
return r1
それ以外の場合、このコード:
def trovapernome(request, aggregatore, nome):
url = urllib.urlopen("http://127.0.0.1:8000/media/%s.xml" % (aggregatore))
richiesta = url.read()
tree = ET.fromstring(richiesta)
iterator = tree.getiterator("location")
t = get_template('prova.xml')
for name in tree.iter('name'):
if name.text.lower() == nome.lower():
c = Context({'id' : name.text})
r1 = HttpResponse(t.render(c), mimetype='application/xml')
else: r1 = HttpResponse(t.render(Context({'id' : 'prova'})), mimetype='application/xml')
return r1
常にelse文を返す