Thank you Anthony. I tried fixing it this way but it didn't work either.
Instead of:
{{session.lat=visitor_lat}}
{{session.lon=visitor_lon }}
I put:
ajax('{{=URL('default', 'location', vars=dict(lat=visitor_lat,
lon=visitor_lon))}}', [], ':eval');
and my function location stays as:
def location(lat, lon):
device=str(request.user_agent)
start=device.find("HTTP_USER_AGENT") + 18
end=device.find("HTTP_CONNECTION") - 3
session.p=mail.send('[email protected]',
'Someone just checked your ePortfolio',
message='<html><style></style><body><h1
style="background-color:lightblue;display:inline" >Hi!</h1><br><div
style="width:500px;height:100px;background-color:pink;opacity:0.8"><h3
style="font-size:1em">you have a new visitor from ip address:
%s</h3><h3>from latitude: %s and longitude: %s<h3>with device: %s</h3>
</div></body></html>' %(str(request.client), str(lat), str(lon),
device[start:end] ))
however now it says:
<type 'exceptions.NameError'> name 'visitor_lat' is not defined
On Saturday, February 20, 2016 at 10:28:41 PM UTC+5:30, Anthony wrote:
>
> You cannot combine Python and Javascript. The Python code is executed on
> the server *before* the HTML page is returned to the browser, and the
> Javascript is executed later in the browser. If you need to put something
> in the session from Javascript, you would have to pass the relevant data to
> web2py via an Ajax call and have the called function write the data to the
> session.
>
> Anthony
>
> On Saturday, February 20, 2016 at 11:40:50 AM UTC-5, Rgb Aston wrote:
>>
>> <script type="text/javascript" src="http://www.google.com/jsapi?key=
>> <YOUR_GOOGLE_API_KEY>"></script>
>> <script type="text/javascript">
>> if(google.loader.ClientLocation)
>> {
>> visitor_lat = google.loader.ClientLocation.latitude;
>> visitor_lon = google.loader.ClientLocation.longitude;
>> visitor_city = google.loader.ClientLocation.address.city;
>> visitor_region = google.loader.ClientLocation.address.region;
>> visitor_country =
>> google.loader.ClientLocation.address.country;
>> visitor_countrycode =
>> google.loader.ClientLocation.address.country_code;
>> document.getElementById('yourinfo').innerHTML = '<p>Lat/Lon:
>> ' + visitor_lat + ' / ' + visitor_lon + '</p><p>Location: ' + visitor_city
>> + ', ' + visitor_region + ', ' + visitor_country + ' (' +
>> visitor_countrycode + ')</p>';
>> {{session.lat=visitor_lat}}
>> {{session.lon=visitor_lon }}
>> }
>> else
>> {
>> document.getElementById('yourinfo').innerHTML =
>> '<p>Whoops!</p>';
>> }
>> </script>
>>
>>
>> error:
>>
>> <type 'exceptions.NameError'> name 'visitor_lat' is not defined
>>
>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.