python - 我怎样才能在 flask 中调整谷歌地图的大小?

标签 python flask jinja2

我正在使用一个开放源代码来使用 Google Map API,但我不知道如何调整 map 的大小。这是我的代码。请帮助我。

index.html

<body><div>{{sndmap.html}}</div></body>
main.py

@app.route('/')
def index():

    sndmap = Map(
        identifier="sndmap",
        varname="sndmap",
        lat=37.4419,
        lng=-122.1419,
        markers=[(37.4419, -122.1419), (37.4500, -122.1350), (37.4300, -122.1400, "Hello World")]
    )

    return render_template('index.html', sndmap=sndmap, GOOGLEMAPS_KEY=request.args.get('apikey'))

最佳答案

您可以轻松地包含内联样式,但添加样式表在很大程度上被认为是最易于维护的方法。

这是通过给你想要的标签一个类来完成的。然后将 css 样式表链接到您的 html 并根据需要更新 css。

我已经包括了一个例子。

projectroot/index.html

<html lang="en">
<head>
    <link rel="stylesheet" type="text/css"
          href="{{ url_for('static', filename='style/style.css') }}">
</head>
<!-- Other html -->
<body>
    <div class="google-map">
      {{ sndmap.html }}
    </div>
</body>
<!-- Other html -->
</html>

projectroot/static/styles/style.css

/* More css */

.google-map {
   max-width: 500px;
   max-height: 200px;
}

/* More css */

这不应该逐字复制,因为您需要尝试使用确切的样式来实现您想要的外观。通过标准 css 的自定义选项数量是无穷无尽的。我建议查找常见模式并处理您喜欢的内容。

关于python - 我怎样才能在 flask 中调整谷歌地图的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60096189/

相关文章:

Django:切换到 Jinja2?

java - Java 中的 DESede 和 Python 中的 3des

python - 是否可以处理包含字符串和数字的矩阵?

python - matplotlib 和/或 seaborn 中旋转轴标签的均匀间距

python - Flask 教程 : AttributeError teardown_appcontext

javascript - Google 图表 - 无效语法或意外标记

python - Django 自定义登录表单显示额外字段

python - Flask-Babel 不使用可插入 View 进行翻译

python - flask : Decorator to test query string arguments

javascript - 动态传递值(例如 : innerHTML) to another element as a value