How to create YOUR own cryptocurrency!!!
Part - 5: Landing page and Database Access
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😊😊.
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.
from flask import Flask, render_template
def index():
return render_template('index.html')
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.
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’.
pip install Flask-MySQLdb
And I have added below code in app.py to set MySQL properties
app.config['MYSQL_HOST'] = 'localhost'
app.config['MYSQL_USER'] = 'root'
app.config['MYSQL_PASSWORD'] = ''
app.config['MYSQL_DB'] = 'crypto'
app.config['MYSQL_CURSORCLASS'] = 'DictCursor'mysql = MySQL(app)
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,
use crypto; //remember to switch to our database
create table users (name varchar(30), email varchar(30), username varchar(30), password varchar(100));
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.
Finally our app.py with db access will looks like 😍😍
Hence accessing our application will create a new table ‘demo’ and insert a dummy value into it.
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
- What is a Flash loan?
- The Best Crypto Trading Bot | Grid Trading
- 3Commas Review | Pionex Review | Coinrule review
- AAX Exchange Review | Deribit Review |FTX Crypto Exchange Review
- NGRAVE ZERO review
- Bybit Exchange Review | Bityard Review | Interdax Review
- 3Commas vs Cryptohopper
- The Best Bitcoin Hardware wallet | BitBox02 Review
- Ledger vs Ngrave | ledger nano s vs x
- Crypto Copy Trading Platforms | Bityard copy trading
- Vauld Review | YouHodler Review | BlockFi Review
- The Best Crypto Tax Software | CoinTracking Review
- Best Crypto Lending Platforms
- Ledger Nano S vs Trezor one vs Trezor T vs Ledger Nano X
- BlockFi vs Celsius | Hodlnaut Review
- Bitsgap review | Quadency Review
- Ellipal Titan Review | SecuX Stone Review
- DEX Explorer and Blockchain APIs
- Best Blockchain Analysis Tools
- Crypto arbitrage guide: How to make money as a beginner
- Best Crypto Charting Tool | Best Crypto Exchange
- What are the best books to learn about Bitcoin?