0
FlaskとPython3で作成したアプリケーションをGitHubページで公開しましたが、back
をクリックすると、そのアプリのルートの代わりにhttps://jurestabuc.github.io/
に戻りますhttps://jurestabuc.github.io/news-terror-app/build/index.html
。GithHubページ - インデックスに戻ることはありません。
誰かが私が間違っていることを教えてくれる?
これは、詳細ページです:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}" />
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
<title>Terror</title>
</head>
<body>
<header>
<h1>In {{ object.iyear }}, {{ object.nkill }} people died in attacks in {{ object.city }}, {{ object.country_txt }}. The attack was carried out by {{ object.gname }}.</h1>
</header>
<div id="map" style="width:100%; height:300px;"></div>
<p><a href="/">« Back</a></p>
<script type="text/javascript">
var map = L.map("map").setView([{{ object.latitude }}, {{ object.longitude }}], 16);
var osmLayer = new L.TileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution: 'Data, imagery and map information provided by <a href="http://www.openstreetmap.org/" target="_blank">OpenStreetMap</a>.'
});
map.addLayer(osmLayer);
var marker = L.marker([{{ object.latitude }}, {{ object.longitude }}]).addTo(map);
</script>
</body>
</html>
インデックスページ:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}" />
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
<title>Terror</title>
</head>
<body>
<!-- <nav>
<a href="">
<img src="">
</a>
</nav> -->
<header>
<h1>50 worst acts of terrorism in Western Europe</h1>
<div class="byline">
By <a href="https://twitter.com/JureStabuc">Jure Stabuc</a>
</div>
</header>
<div id="map" style="width:100%; height:400px;"></div>
<table border=1 cellpadding=7>
<tr>
<th>City</th>
<th>Country</th>
<th>Year</th>
<th>Type of attack</th>
<th>Target</th>
<th>Number of dead</th>
<th>Terrorist organisation</th>
<!-- <th>Motive</th> -->
<!-- <th>Weapons</th> -->
</tr>
{% for obj in object_list %}
<tr>
<td><a href="{{ obj.id }}/">{{ obj.city }}</a></td>
<td><a href="{{ obj.id }}/">{{ obj.country_txt}}</a></td>
<td><a href="{{ obj.id }}/">{{ obj.iyear }}</a></td>
<td><a href="{{ obj.id }}/">{{ obj.attacktype1_txt}}</a></td>
<td><a href="{{ obj.id }}/">{{ obj.target1 }}</a></td>
<td><a href="{{ obj.id }}/">{{ obj.nkill }}</a></td>
<td><a href="{{ obj.id }}/">{{ obj.gname }}</a></td>
<!-- <td><a href="{{ obj.id }}/">{{ obj.motive }}</a></td> -->
<!-- <td><a href="{{ obj.id }}/">{{ obj.weapdetail}}</a></td> -->
</tr>
{% endfor %}
</table>
<script type="text/javascript">
var map = L.map("map").setView([50.0000, 20.0000], 4);
var osmLayer = new L.TileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution: 'Data, imagery and map information provided by <a href="http://www.openstreetmap.org/" target="_blank">OpenStreetMap</a>.'
});
map.addLayer(osmLayer);
var data = {
"type": "FeatureCollection",
"features": [
{% for obj in object_list %}
{
"type": "Feature",
"properties": {
"city": "{{ obj.city }}",
"id": "{{ obj.id }}"
},
"geometry": {
"type": "Point",
"coordinates": [{{ obj.longitude }}, {{ obj.latitude }}]
}
}{% if not loop.last %},{% endif %}
{% endfor %}
]
};
var dataLayer = L.geoJson(data, {
onEachFeature: function(feature, layer) {
layer.bindPopup(
"<a href = '" + feature.properties.id + "/'>" + feature.properties.city + "</a>"
);
}
});
map.addLayer(dataLayer);
</script>
</body>
</html>
app.py:
import csv
from flask import Flask
from flask import abort
from flask import render_template
app = Flask(__name__)
def get_csv():
csv_path ="./static/top50weu.csv"
#adding encoding because of issues with it. http://stackoverflow.com/questions/12468179/unicodedecodeerror-utf8-codec-cant-decode-byte-0x9c
csv_file = open(csv_path, "r", encoding="latin-1")
#parsed and returned as a list of dictionaries
csv_obj = csv.DictReader(csv_file)
csv_list = list(csv_obj)
return csv_list
@app.route("/")
def index():
template ="index.html"
object_list = get_csv()
return render_template(template, object_list=object_list)
@app.route("/<row_id>/")
def detail(row_id):
template = "detail.html"
object_list = get_csv()
for row in object_list:
if row["id"] == row_id:
return render_template(template, object=row)
abort(404)
if __name__ == "__main__":
#Fire up the Flask test server
app.run(debug=True, use_reloader=True)
freeze.py:
from flask_frozen import Freezer
from app import app, get_csv
freezer = Freezer(app)
app.config['FREEZER_RELATIVE_URLS'] = True
@freezer.register_generator
def detail():
for row in get_csv():
yield {"row_id": row["id"]}
if __name__ == '__main__':
freezer.freeze()
ローカルではすべて問題ありません。例はappにあります。ありがとうございました!