[Python] Web application from 0! Hands-on (2) -Hello World-

Overview

I had the opportunity to create a web application from scratch with Python, so as a summary! This article describes how to do Hello World with API.

I want this person to read

goal

The goal is to create a web app with CURD functionality using HTML, CSS, JavaScript, Python, and SQL.

Things necessary

1. Folder structure

The folders and files created this time are as follows.

todo/  └ api/   └ index.py

  1. Bottle A web framework is a major factor when creating a web application. Bottle is a lightweight web framework for Python. Bottle: Python Web Framework — Bottle 0.13-dev documentation There are other well-known frameworks such as Django and Flask, but this time I decided to use Bottle, which is lightweight and easy because it is small. It also supports an interface called WSGI. Normally, when you place a web application on a server, you have to consider various things, but you can make a web application quite easily! That is (roughly)

The features of each framework are for reference below.

3. Install Bottle

Open a command prompt as an administrator and execute the following command. Only this. pip install bottle

4. Try Hello World

Create a working folder and open it with VS Code. Then, create the following folders and files. (.vscode is generated by VS Code without permission) todo/  └ api/   └ index.py

image.png

Then write the code in index.py.

index.py


# -*- coding:utf-8 -*-

#Load an external package
from bottle import route, run

# @to route/If set to hello, http://localhost:8080/Can be accessed with hello
@route('/hello')
def hello():
    # Hello World!Returns the string
    return "Hello World!"

#Web server execution configuration
#URL"http://[host]:[port]/[route]"Becomes the composition of
run(host='localhost', port=8080, debug=True)

Press F5 and select Python File. image.png

http://localhost:8080/hello When you visit, you should see "Hello World!"!

Summary

As the first step of API implementation, I tried Hello World!

next time···

Connect to the database from the API!

Recommended Posts

[Python] Web application from 0! Hands-on (2) -Hello World-
[Python] Web application from 0! Hands-on (3) -API implementation-
[Python] Web application from 0! Hands-on (4) -Data molding-
[Python] Web application from 0! Hands-on (0) -Environmental construction-
[Python] Web application from 0! Hands-on (1) -Design, DB construction-
Study from the beginning of Python Hour1: Hello World
Web application with Python + Flask ② ③
Python starting with Hello world!
Web application with Python + Flask ④
Web application development memo in python
[Note] Hello world output with python
cout << "Hello, World! \ N" in python
Python #Hello World for super beginners
From building a Python environment for inexperienced people to Hello world
Hello world
Python: Reading JSON data from web API
[Python] A quick web application with Bottle!
[Python] Web application design for machine learning
Flask tutorial (from installation to hello world)
Run a Python web application with Docker
How to display Hello world in python
C language to see and remember Part 1 Call C language from Python (hello world)
Hello World and face detection with OpenCV 4.3 + Python
Run a Python script from a C # GUI application
Python 1 person study session: 1st "Running Python ~" Hello world ""
How to open a web browser from python
Data acquisition from analytics API with Google API Client for python Part 2 Web application
From Kivy environment construction to displaying Hello World
Pymacs hello world
Say hello to the world with Python with IntelliJ
sql from python
Hello World with nginx + uwsgi + python on EC2
Steps to develop a web application in Python
[Python] Flow from web scraping to data analysis
MeCab from Python
Create a one-file hello world application with django
First python ① Environment construction with pythonbrew & Hello World !!
Get only articles from web pages in Python
cython hello world
Extract data from a web page with Python
Hello World is a simple web server that follows WSGI (Web Server Gateway Interface) in Python.
2014 Web Application Framework Trends (PHP / Java / Ruby / Python / Perl)
(Python) Try to develop a web application using Django
Parse and visualize JSON (Web application ⑤ with Python + Flask)
RaspberryPi3 (STRETCH) setup from OS installation to Hello World
Launch a Python web application with Nginx + Gunicorn with Docker
Web application made with Python3.4 + Django (Part.1 Environment construction)
Touch MySQL from Python 3
Django python web framework
web2py memo: Hello World
Operate Filemaker from Python
Use fluentd from python
Access bitcoind from python
Changes from Python 3.0 to Python 3.5
Changes from Python 2 to Python 3.0
Python from or import
hello world with ctypes
Use MySQL from Python
RabbitMQ Tutorial 1 ("Hello World!")
Run python from excel
Install python from source