I made a simple book application with python + Flask ~ Introduction ~

Introduction

This time, as the title says, I will make a simple book management application using python and Flask.

I'm currently studying programming at university, but I've only made programs and reports that I was told to "make and submit" in a lecture. I have almost never created an app or program by thinking from scratch.

So, this time I'm going to make a web application from scratch for the first time. I create it while referring to various sites, but I think there are probably various ways to write a program that is more suitable than the one I created. So, at that time, you can point it out.

I'm thinking of posting what I didn't understand or stumbled upon when making this web app, so if you want to make a book management app like me easily, please refer to it. I would appreciate it if you could.

Then, I will actually make it.

Premise

This time, I will make a web application that manages books. We will continue to create web applications while proceeding with the following assumptions, so thank you.

Also, since I updated to Catalina, I am executing commands with zsh instead of bash. So the `$ mark is now the% mark`. In the execution result,% is displayed as \ $ when the command is executed, but I think it's okay if you don't mind. It may be incorrect information, so if it is incorrect, please correct it.

MacBook Air / macOS Catalina version 10.15.1 python 3.7.4 Flask 1.1.1 mysql Ver 8.0.18 for osx10.15 on x86_64 (Homebrew) mysqlclient 1.4.6

Introducing libraries and MySQL

First of all, we will introduce the database and library written on the premise. I will proceed with the introduction of python assuming that it has already been introduced this time. Also, since this is an introductory edition, we will do the following parts.

  1. Create a virtual environment with venv
  2. Install the required libraries using pip
  3. Introduction of MySQL

Building a virtual environment

Move to the directory you want to work in in the order of the following commands, build a virtual environment, and activate to work.

terminal


$ cd {Working directory path}
$ python3 -m venv {Virtual environment name}
$ . {Virtual environment name}/bin/activate

I did the following:

terminal


$ cd ~/Desktop/work
$ python3 -m venv venv
$ . venv/bin/activate

Introducing the library

Here, if you execute pip3 list to check the library, you will see the following execution result. (Because my real name is in [name]. I'm lying down.) If necessary, run `` `pip3 install --upgrade pip```.

terminal


({Virtual environment name}) [name]@Hello-World {Working directory name} % pip3 list
Package    Version
---------- -------
pip        19.3.1 
setuptools 39.0.1 
({Virtual environment name}) [name]@Hello-World {Working directory name} % 

In my case, the virtual environment name is venv and the working directory name is work, so it looks like the following. After that, it will be executed in various ways in the following virtual environment, so if you have changed each name, please read it as appropriate.

terminal


(venv) [name]@Hello-World work % pip3 list
Package    Version
---------- -------
pip        19.3.1 
setuptools 39.0.1 
(venv) [name]@Hello-World work % 

We will install the necessary libraries from here. Execute the following command.

terminal


$ pip3 install flask
$ pip3 install request
$ pip3 install mysqlclient

And if you run pip3 list again, you should see something like the following. This completes the installation of the library.

terminal


[name]@Hello-World ~ % cd Desktop/work 
[name]@Hello-World work % . venv/bin/activate        
(venv) [name]@Hello-World work % pip3 list           
Package      Version  
------------ ---------
Click        7.0      
Flask        1.1.1    
get          2019.4.13
itsdangerous 1.1.0    
Jinja2       2.10.3   
MarkupSafe   1.1.1    
mysqlclient  1.4.6    
pip          19.3.1   
post         2019.4.13
public       2019.4.13
query-string 2019.4.13
request      2019.4.13
setuptools   40.8.0   
Werkzeug     0.16.0   
(venv) [name]@Hello-World work % 

Introduction of MySQL

Finally, we will introduce the MySQL used this time using Homebrew. If you have homebrew, please run only the second one.

terminal


$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
$ brew install mysql

At the end

This time, the introduction is biased, so this is the end. Next time, I will actually create a program. Thank you for watching.

Recommended Posts

I made a simple book application with python + Flask ~ Introduction ~
I made a simple blackjack with Python
I made a Mattermost bot with Python (+ Flask)
I made a fortune with Python.
I made a daemon with Python
I made a simple typing game with tkinter in Python
I made a character counter with Python
I made a Hex map with Python
I made a roguelike game with Python
I made a configuration file with Python
I made a WEB application with Django
I made a neuron simulator with Python
I made a simple circuit with Python (AND, OR, NOR, etc.)
A super introduction to Django by Python beginners! Part 5 I made a super simple diary application with a class-based general-purpose view
I made a Nyanko tweet form with Python, Flask and Heroku
[Python] I made an image viewer with a simple sorting function.
I made a competitive programming glossary with Python
I made a weather forecast bot-like with Python.
[Python] I made a Youtube Downloader with Tkinter.
I made a simple Bitcoin wallet with pycoin
I made a bin picking game with Python
I tried to discriminate a 6-digit number with a number discrimination application made with python
I made blackjack with python!
I made a python text
Web application with Python + Flask ② ③
I made blackjack with Python.
I made wordcloud with Python.
Web application with Python + Flask ④
I made a Twitter BOT with GAE (python) (with a reference)
I made a household account book bot with LINE Bot
I made a Christmas tree lighting game with Python
I made a Python3 environment on Ubuntu with direnv.
I made a LINE BOT with Python and Heroku
I tried to make a simple mail sending application with tkinter of Python
[ES Lab] I tried to develop a WEB application with Python and Flask ②
I made LINE-bot with Python + Flask + ngrok + LINE Messaging API
Creating a simple app with flask
I made a web application that maps IT event information with Vue and Flask
I made a puzzle game (like) with Tkinter in Python
Application development with Docker + Python + Flask
I made a package that can compare morphological analyzers with Python
Let's make a WEB application for phone book with flask Part 1
Let's make a WEB application for phone book with flask Part 2
I made a lot of files for RDP connection with Python
I made a shuffle that can be reset (reverted) with Python
I tried to make a 2channel post notification application with Python
[Introduction] I want to make a Mastodon Bot with Python! 【Beginners】
Let's make a WEB application for phone book with flask Part 3
I tried to make a todo application using bottle with python
Let's make a WEB application for phone book with flask Part 4
I made a poker game server chat-holdem using websocket with python
I made a segment tree with python, so I will introduce it
Spiral book in Python! Python with a spiral book! (Chapter 14 ~)
Creating a simple PowerPoint file with Python
A simple RSS reader made with Django
I made a payroll program in Python!
Simple Slack API client made with Python
I drew a heatmap with seaborn [Python]
I tried a functional language with Python
[Python] A quick web application with Bottle!
Create a simple web app with flask