[PYTHON] code-server Local environment (5) Let's prepare an MVC environment including DB (2)

This is the 4th day article of Advent Calender on the 2019 code-server. This time as well, I will explain what is code-server?

(1) What is code-server? (2) Create your own code-server environment with Docker (3) Try using VSCode Plugin (4) Let's prepare an MVC environment including DB etc. (1) (5) Let's prepare an MVC environment including DB etc. (2) (6) Let's prepare an MVC environment including DB etc. (3) (7) Let's prepare an MVC environment including DB etc. (4) (8) Let's prepare an MVC environment including DB etc. (5) (9) Let's prepare an MVC environment including DB etc. (6) (10) Bonus

(NEXT->) Online environment version 1st day Improve the work environment

(..) To build locally including environment such as DB (..) How to put it online? (..) How to work with the latest trendy environment such as K8S? (..) I want to modify Code-Server to make it better

Continuing from the last time, let's run flask.

What is this time?

Terminal is convenient. Bash is recommended

Since it is VSCode, you can use Terminal. You can operate Linux with cli. So, you can launch ssh separately

dockeer-compose exec -it app bash

There is no need to launch Terminal separately. I'm using bash, so first

bash

I am trying to enter.

What is Flask

A lightweight web framework. You can create a web page very easily.

https://github.com/pallets/flask

Let's create a Flask environment !!

Screen Shot 2019-12-05 at 0.55.13.png

I will try it for the first time from the continuation of the last time.

Create requirements.txt.

requirements.txt


flask

On the command line

pip install -r requirements.txt 

Let's write the code.

main.py


from flask import Flask

app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello, World!"

app.run("0.0.0.0",port=8080)

Let's do it !!


$ python main.py 
 * Serving Flask app "main" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://0.0.0.0:8080/ (Press CTRL+C to quit)

When I open http://127.0.0.1:8080/ in a browser, it says Hello, World!

Screen Shot 2019-12-05 at 1.11.23.png

next time

Let's create a db environment

PS

Source

https://github.com/kyorohiro/advent-2019-code-server

Recommended Posts

code-server Local environment (9) Let's prepare an MVC environment including DB (6)
code-server Local environment (4) Let's prepare an MVC environment including DB (1)
code-server Local environment (5) Let's prepare an MVC environment including DB (2)
code-server online environment (6) Let's automate
code-server Local environment (3) Try using VSCode Plugin