【发布时间】:2014-12-02 03:53:52
【问题描述】:
我正在尝试使用 Flask 构建网站。我对客户端知之甚少。我正在尝试构建一个 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 %}
我的意见.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中的调用方法?
【问题讨论】:
标签: javascript jquery python flask jinja2