From 2ab2ffba1d52f7015de0bbc444fae7d07c5eff69 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Mon, 8 Jun 2015 07:43:56 -0500 Subject: better index and template, example --- rpcblockchainexplorer/api.py | 19 +++++++++++++++++++ rpcblockchainexplorer/templates/blocks.html | 4 ++++ rpcblockchainexplorer/templates/body.html | 15 --------------- rpcblockchainexplorer/templates/layout.html | 15 +++++++++++++++ 4 files changed, 38 insertions(+), 15 deletions(-) delete mode 100644 rpcblockchainexplorer/templates/body.html create mode 100644 rpcblockchainexplorer/templates/layout.html diff --git a/rpcblockchainexplorer/api.py b/rpcblockchainexplorer/api.py index 8d9ae17..666500c 100644 --- a/rpcblockchainexplorer/api.py +++ b/rpcblockchainexplorer/api.py @@ -35,6 +35,7 @@ from flask import ( Blueprint, request, g, + render_template, ) api = Blueprint("api", __name__, url_prefix="") @@ -175,3 +176,21 @@ def create_api_endpoints(commands=ALLOWED_COMMANDS): # the endpoints to the blueprint, which can then be attached to flask # application instances. create_api_endpoints() + +# TODO: convert from the above format to the following format for each +# API command. Unfortunately it seems that there must be a custom template to +# display the relevant content. +@api.route("/") +def index(): + blocks = [] + + blockcount = g.bitcoin_rpc_client.getblockcount() + + for block_index in range(0, blockcount): + blockhash = g.bitcoin_rpc_client.getblockhash(block_index) + blocks.append({ + "height": block_index, + "hash": blockhash, + }) + + return render_template("blocks.html", blocks=blocks) diff --git a/rpcblockchainexplorer/templates/blocks.html b/rpcblockchainexplorer/templates/blocks.html index c89677a..cb29ada 100644 --- a/rpcblockchainexplorer/templates/blocks.html +++ b/rpcblockchainexplorer/templates/blocks.html @@ -1,3 +1,6 @@ +{% extends "layout.html" %} + +{% block content %} @@ -10,3 +13,4 @@ {% endfor %}
blockheight
+{% endblock %} diff --git a/rpcblockchainexplorer/templates/body.html b/rpcblockchainexplorer/templates/body.html deleted file mode 100644 index e012001..0000000 --- a/rpcblockchainexplorer/templates/body.html +++ /dev/null @@ -1,15 +0,0 @@ - - - - {% if title %}{{ title }}{% else %}rpcblockchainexplorer{% endif %} - - - {% include "header.html" %} - -
- {% block content %}{% endblock %} -
- - {% include "footer.html" %} - - diff --git a/rpcblockchainexplorer/templates/layout.html b/rpcblockchainexplorer/templates/layout.html new file mode 100644 index 0000000..e012001 --- /dev/null +++ b/rpcblockchainexplorer/templates/layout.html @@ -0,0 +1,15 @@ + + + + {% if title %}{{ title }}{% else %}rpcblockchainexplorer{% endif %} + + + {% include "header.html" %} + +
+ {% block content %}{% endblock %} +
+ + {% include "footer.html" %} + + -- cgit v1.2.3