Nov-01-2018, 11:55 AM
Hi. I am developing a web-app which contains map api in order to let the user select his location. The following code is about this procedure;
app = Flask(__name__) C = cookies.SimpleCookie() C['enlem'] = 39.9215219 C['boylam'] = 32.8537929 C['UTC_Offset'] = 3 C['yukseklik'] = 0 C['lokasyon'] = "Ankara, Türkiye" C['Adres'] = "Ankara,Türkiye" @app.route('/Konum_Belirle', methods = ['GET','POST']) def Konum_Belirle(): tf = TimezoneFinder() utc = pytz.utc resp = make_response(render_template('Konum_Degistir.html')) if request.method == "POST": adres = request.form.get('Adres') geolocator = Nominatim(user_agent="specify_your_app_name_here", timeout=5) lokasyon = geolocator.geocode(adres) C['lokasyon'] = lokasyon resp.set_cookie('lokasyon',C['lokasyon'].value) if C['lokasyon'].value == None: C['lokasyon']="Adres Bulunamadı." resp.set_cookie('lokasyon',C['lokasyon'].value) C['UTC_Offset']= "Zaman dilimi bulunamadı!" C['enlem'] = 0 resp.set_cookie('enlem',C['enlem'].value) C['boylam'] = 0 resp.set_cookie('boylam',C['boylam'].value) else: C['enlem']=lokasyon.latitude resp.set_cookie('enlem',C['enlem'].value) C['boylam'] = lokasyon.longitude resp.set_cookie('boylam',C['boylam'].value) today = datetime.now() tz_target = timezone(tf.certain_timezone_at(lat=float(C['enlem'].value), lng=float(C['boylam'].value))) if tz_target == None: C['UTC_Offset']= "Zaman dilimi bulunamadı!" else: today_target = tz_target.localize(today) today_utc = utc.localize(today) C['UTC_Offset'] = (today_utc - today_target).total_seconds() / (60*60) enlem = request.cookies.get('enlem') boylam = request.cookies.get('boylam') lokasyon = request.cookies.get('lokasyon') UTC_Offset = float(C['UTC_Offset'].value) return render_template('Konum_Degistir.html', adres = lokasyon, enlem = enlem, boylam = boylam, yukseklik=C['yukseklik'].value\ UTC_Offset = UTC_Offset)I need to save the user location input, such that his address, and determine the latitude and longitude of his location and then save these variables into his cookies and reach it from another route function, but when I tried to save them into cookies, the request.cookies.get returns None everytime. My web-app does not contain any log-in feature. My question is how can I save this input for every individual user and reach them. Are the cookies solution for this problem or are there any other alternatives ?