0
我想建立使用烧瓶内的站点。我对客户端知之甚少。我正在尝试构建一个Jinja2模板,该模板运行一个脚本,该脚本提供了用户的经度和纬度。问题是我有经度和纬度,但我不知道如何将数据从脚本传回服务器端。传输客户端数据到服务器端的瓶
这是我base.html文件
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title>Welcome to Tumu's App</title>
</head>
<body>
<p>
Hello. Lets share between close peoples.
</p>
<script type="text/javascript">
navigator.geolocation.getCurrentPosition(function (position) {
alert(position.coords.latitude + ',' + position.coords.longitude);
}, function (error) {
alert(error.code);
}, {enableHighAccuracy: true, maximumAge: 0});
</script>"
<div>Share your location: <a href="/">Home</a></div>
<hr>
{% block content %}{% endblock %}
</body>
</html>
我的test.html
{% extends "base.html" %}
{% block content %}
<h1>Hi, {{ user.nickname }}!</h1>
{% for post in posts %}
<div><p>{{ post.author.nickname }} says: <b>{{ post.body }}</b></p></div>
{% endfor %}
{% endblock %}
我views.py
from app import app
from app import methods
from flask import render_template
# default route
@app.route('/')
def default():
return render_template('base.html')
# generic test
@app.route('/test')
def test():
user = {'nickname': 'rmad'} # fake user
return render_template('test.html', title='Flask Home',user=user)
如何是否将数据从脚本传输到views.py中的调用方法?
谢谢,但不幸的是它没有发挥出来。 请检查是否我已经申请了变化适当 我base.html文件片断 <脚本类型= “文/ JavaScript的”> navigator.geolocation.getCurrentPosition(函数(位置){ \t \t $阿贾克斯({ \t \t \t类型: 'POST', \t \t \t \t URL: '/地点', \t \t \t \t数据:JSON.stringify({ '纬度':position.coords.latitude, '经度':position.coords.longitude },NULL, '\ T'), \t \t \t \t contentType:'application/json; charset = UTF-8' \t \t}); \t \t},函数(误差){ \t \t警报(error.code); \t \t},{enableHighAccuracy:真,maximumAge:0}); “ 我添加/位置路线views.py中。 – rmad17 2014-12-02 19:47:45
它没有工作?有什么不工作?你得到什么错误? – nathancahill 2014-12-03 08:20:41
任何错误。我想打印的经度和纬度。没。 我做了我的views.py的是,我添加了/位置路线,但我仍在使用默认路由来渲染base.html文件。我是不是做错了什么? – rmad17 2014-12-03 19:15:47