I have this code to get download links via libgen api.
@app.route("/api/default")
def titleSearch():
title = request.args.get('query')
s = LibgenSearch()
results = s.search_title(title)
item_to_download = results[0]
download_links = s.resolve_download_links(item_to_download)
return render_template(
"results.html", results=results, download_links=download_links, title=title,
)
results.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>SUSBOOKS</title>
<link rel="stylesheet" href="{{ url_for('static', filename='bootstrap.min.css') }}" />
<link rel="stylesheet" href="{{ url_for('static', filename='mdb.dark.min.css') }}" />
<link rel="stylesheet" href="{{ url_for('static', filename='all.min.css') }}" />
<style>
body {
background-color:#000000 ;
}
</style>
</head>
<body>
<p>{{download_links}}</p>
</body>
download_links comes out as
{'GET': 'http://62.182.86.140/main/265000/ef7a3a2ecf51fa41f621f4e8b17df828/(Saddleback's Focus on Reading Study Guides) Lisa Mccarty - To Kill a Mockingbird-Saddleback Educational Publishing, Inc. (2006).pdf', 'Cloudflare': 'https://cloudflare-ipfs.com/ipfs/bafykbzacebtnktd2zpvrcygswfcsr6wfft6jjyes6qi7f4mmottq3lebrgpsc?filename=(Saddleback's Focus on Reading Study Guides) Lisa Mccarty - To Kill a Mockingbird-Saddleback Educational Publishing, Inc. (2006).pdf', 'IPFS.io': 'https://ipfs.io/ipfs/bafykbzacebtnktd2zpvrcygswfcsr6wfft6jjyes6qi7f4mmottq3lebrgpsc?filename=(Saddleback's Focus on Reading Study Guides) Lisa Mccarty - To Kill a Mockingbird-Saddleback Educational Publishing, Inc. (2006).pdf'}{'GET': 'http://62.182.86.140/main/265000/ef7a3a2ecf51fa41f621f4e8b17df828/(Saddleback's Focus on Reading Study Guides) Lisa Mccarty - To Kill a Mockingbird-Saddleback Educational Publishing, Inc. (2006).pdf', 'Cloudflare': 'https://cloudflare-ipfs.com/ipfs/bafykbzacebtnktd2zpvrcygswfcsr6wfft6jjyes6qi7f4mmottq3lebrgpsc?filename=(Saddleback's Focus on Reading Study Guides) Lisa Mccarty - To Kill a Mockingbird-Saddleback Educational Publishing, Inc. (2006).pdf', 'IPFS.io': 'https://ipfs.io/ipfs/bafykbzacebtnktd2zpvrcygswfcsr6wfft6jjyes6qi7f4mmottq3lebrgpsc?filename=(Saddleback's Focus on Reading Study Guides) Lisa Mccarty - To Kill a Mockingbird-Saddleback Educational Publishing, Inc. (2006).pdf'}
How would I go about making it output just the links hyperlinked so users can just click to download them?
CodePudding user response:
In response, you have a dictionary which is key-value pairs. reading key value of a dictionary:
my_dict = {
"link_1": "example_1.com",
"link_2": "example_2.com"
}
for key, value in my_dict.items():
print(key, value)
output
link_1, example_1.com
link_2, example_2.com
now you flask template you can do
{% for key, value in my_dict.items() %}
<p>{{ key }}, {{ value }}</p>
{% endfor %}
instead of
<p>{{ my_dict }}</p>