Viikkotehtävä 2 on nyt arvioitu.
Oman arvionne näette täältä:
https://appro.mit.jyu.fi/cgi-bin/ties4080/ilmo/ilmo.cgi/omat
Aika monella oli urlien sisältö epävalidi. Urlit kannattaa rakentaa tehtävänannossa vinkattua urllib.parse.urlencode-funktiota käyttäen:
https://docs.python.org/3/library/urllib.parse.html#urllib.parse.urlencode
Esimerkkejä:
https://docs.python.org/3/library/urllib.request.html#urllib-examples
esim.
#muista serialisointi json-muotoon, kos kyseessä muuta kuin string tai int tila = {"foo": "bar", "taulukko": json.dumps([1,2,3,4,5]), "testi": 1}
querystring = urllib.parse.urlencode( json.dumps(tila) )
ja nyt querystring on seuraavanlainen:
'foo=bar&taulukko=%5B1%2C+2%2C+3%2C+4%2C+5%5D&testi=1'
Yksittäisen urlin osan voi koodata urllib.parse.quote_plus-funktiolla:
https://docs.python.org/3/library/urllib.parse.html#urllib.parse.quote_plus
huomatkaa, että edellä oleva koodaus tosiaan koskee vain urleja. lomakkeen hidden-kenttään saa vapaammin sijoittaa merkkijonoja, mutta sielläkin pitää muista koodata html:n erikoismerkit. Jinja tekee tämän automaattisesti.
Lisäksi sovelluksen tilan muistamiseen tarvitaan serialisointia, johon myös oli suora vinkki tehtävänannossa. Ts. jos haluat tallentaa monimutkaisempia rakenteita kuin pelkkiä merkkijonoja tai numeroita, on rakenteesi serialisoitava merkkijonoksi:
https://appro.mit.jyu.fi/ties4080/luennot/python/#TOC18