Basic Flask for ML Projects

Saurav Panigrahi
3 min readNov 12, 2018

--

A mini introductory tutorial for Flask

First I assume that Flask has been installed in the computer or else it can be easily done by the command pip install flask .

I made a new dir using mkdir firstSample .

I create a new main python file called app.py the code to which has been given in my Github repository. Inside the app.py we use route method to invoke all the html files to the python code.

snippet of app.py

The other python file which we have created is data.py where I will be saving the contents of my articles in the form of list by assigning them ‘id’ numbers.

snippet of data.py

Basically to import the details of data from data.py to app.py I have used

from data import Articles

Now coming to the part related to HTML / CSS……….

I made a subdirectory within the main directory named templates where I will be saving all my HTML codes.

I have used BOOTSTRAP CDN which is available online to get a basic/ standard framework for my page.

I have created multiple html files and connected them with the main layout.html file using extends method.

SQL part

The SQL commands that I have used for this purpose are as follows-

creating the table users

For setting up the connection of MySql and Flask

pip install flask-mysqldb

Note- There is a chance here of getting some Error such as C++ distributable , so for that we need to make sure all our build files are properly setup.

TIPS and TRICKS

I have purposely used cmd line prompt to a great extent in this mini project so that I can be very much fluent. Some of the useful commands which have come to use are — — —

type nul > filename.extension — — — creates a blank file of corresponding extension

subl filename.py / filename.html — — — directly opens up the editor for us which in my case is Sublime Text

mkdir , dir etc — — — some basic commands.

mysql -u (username set by you) -p (password set by you) — — — for accessing MYSql command line prompt.

GITHUB CODE REPO — —

The code to this work can be found in https://github.com/johnty05/MyFirstFlaskWork

--

--

Saurav Panigrahi

IIM Trichy | VIT Vellore | Ex-BlackRock | YT - @sauravshares