How to create YOUR own cryptocurrency!!!

Part - 5: Landing page and Database Access

Anantha Perumal
Feb 4 · 4 min read

Welcome back, guys🤗🤗…In my previous blogs, we discussed some basic introduction to blockchain, then how blockchain is made after that, we discussed how data in blockchain are almost impossible to change and at last, we discussed hosting our application with flask. Those who missed it please have a look over my previous blogs so that you will enjoy reading here😊😊.

pic source here

What’s our next step here? we are gonna provide database access to our application in this blog💥💥 and to render landing page to our application with login and sign up page, Hence I have designed a simple landing page having options to sign in and sign up. Have a demo here 😍😍!!

In the previous blog, we had hard coded webpage as “<h1>Web app hosted</h1>”, the recommended way is to design your page and to render that page. To render we need to use render_template function from flask package, hence modify your code in app.py with below to render a webpage.

You need to design your webpage in index.html file (you can access my webpage here). Flask needs your file to be placed under a folder with defined names hence follow the folder naming as below.

Project Structure

The conventions are the file given inside render_template must be under templates folder and other files like CSS, JS, images etc should be placed under the static folder and it should be referred in href/src as ‘{{ url_for(‘static’,filename=’<path>’) }}’.

Execute the command python app.py and you can see your webpage rendered at http://localhost:7070 😎😎

Let’s get our hands-on keyboard, we are going to connect our flask application with MySQL database 💾, in order to connect we need to install a package to our virtual environment. Execute the below command in terminal to install ‘Flask-MySQLdb’.

And I have added below code in app.py to set MySQL properties

In the previous blog, we had already created a table ‘Blockchain’ for storing blocks likewise we are going to create a table for storing information about the user by executing below command,

Let’s have our code organized hence we will have a separate file ‘sqlhelpers.py’ to maintain database-related functions. Update sqlhelpers.py with the below code.

sqlhelpers.py

Finally our app.py with db access will looks like 😍😍

app.py

Hence accessing our application will create a new table ‘demo’ and insert a dummy value into it.

Output Screenshot

The above figure explains there is no table named ‘demo’ initially after accessing application @ http://localhost:7070 a new table gets created and some values are populated.

Great job guys, we have granted database access to our application.

For those who want source code, you can access the updated code here.

Thank you so much for spending your valuable time in my blog. Please support me by doing claps at the rate of 1–50 by the way you feel it worth. If you have any doubts regarding this blog or suggestion to improve it please do comment below and share it to those who want to know about blockchain.

Stay tuned for next part as it was going to be more interesting. you can find next part link here when it gets published else follow me to get notified. I will get you things as simple as you could understand😉😉.

Have a good day😊😊

Join Coinmonks Telegram group and learn about crypto trading and investing

Also, Read

Get Best Software Deals Directly In Your Inbox

Coinmonks is a non-profit Crypto educational publication.