はい、要するに、キーと値の前に au が表示される理由を知りたいです。
フォームをレンダリングしています。フォームには、特定のラベル用のチェックボックスと、IP アドレス用の 1 つのテキスト フィールドがあります。キーが list_key にハードコーディングされたラベルであるディクショナリを作成しており、ディクショナリの値はフォーム入力 (list_value) から取得されます。ディクショナリは作成されますが、一部の値では先頭に u が付きます。辞書のサンプル出力は次のとおりです。
{u'1': {'broadcast': u'on', 'arp': '', 'webserver': '', 'ipaddr': u'', 'dns': ''}}
誰かが私が間違っていることを説明してください。pyscripter で同様のメソッドをシミュレートすると、エラーが発生しません。コードを改善するための提案は大歓迎です。ありがとうございました
#!/usr/bin/env python
import webapp2
import itertools
import cgi
form ="""
<form method="post">
FIREWALL
<br><br>
<select name="profiles">
<option value="1">profile 1</option>
<option value="2">profile 2</option>
<option value="3">profile 3</option>
</select>
<br><br>
Check the box to implement the particular policy
<br><br>
<label> Allow Broadcast
<input type="checkbox" name="broadcast">
</label>
<br><br>
<label> Allow ARP
<input type="checkbox" name="arp">
</label><br><br>
<label> Allow Web traffic from external address to internal webserver
<input type="checkbox" name="webserver">
</label><br><br>
<label> Allow DNS
<input type="checkbox" name="dns">
</label><br><br>
<label> Block particular Internet Protocol address
<input type="text" name="ipaddr">
</label><br><br>
<input type="submit">
</form>
"""
dictionarymain={}
class MainHandler(webapp2.RequestHandler):
def get(self):
self.response.out.write(form)
def post(self):
# get the parameters from the form
profile = self.request.get('profiles')
broadcast = self.request.get('broadcast')
arp = self.request.get('arp')
webserver = self.request.get('webserver')
dns =self.request.get('dns')
ipaddr = self.request.get('ipaddr')
# Create a dictionary for the above parameters
list_value =[ broadcast , arp , webserver , dns, ipaddr ]
list_key =['broadcast' , 'arp' , 'webserver' , 'dns' , 'ipaddr' ]
#self.response.headers['Content-Type'] ='text/plain'
#self.response.out.write(profile)
# map two list to a dictionary using itertools
adict = dict(zip(list_key,list_value))
self.response.headers['Content-Type'] ='text/plain'
self.response.out.write(adict)
if profile not in dictionarymain:
dictionarymain[profile]= {}
dictionarymain[profile]= adict
#self.response.headers['Content-Type'] ='text/plain'
#self.response.out.write(dictionarymain)
def escape_html(s):
return cgi.escape(s, quote =True)
app = webapp2.WSGIApplication([('/', MainHandler)],
debug=True)