I made a scaffolding tool for the Python web framework Bottle

create bottle app.png

Do you know Bottle, a web framework?

Django is a well-known web framework for Python, but one of my personal favorite frameworks is Bottle.

You can easily create a web application just by preparing one Python file and HTML file :)

Bottle

You can install Bottle with the following command.

$ pip install bottle

Scaffolding tool

I've created some web applications with Bottle, but they always have the same directory structure.

It's a hassle to create a similar environment every time, so I created a tool that automatically generates folders and files :)

The source code is on GitHub.

When you run the tool (creator.py), you will be asked for the project name and the CSS framework to use.

When the input is completed, it will be automatically generated with the following directory structure.

├── app.py
├── static
│   └── main.css
└── views
     └── index.html

Let's take a look at the generated file.

index.html


<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <link rel="stylesheet" href="../static/main.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/css/bulma.min.css">

    <title>test3</title>

  </head>
  <body>

    <section class="hero is-medium is-primary is-bold">
      <div class="hero-body">
        <div class="container">
          <h1 class="title">
            {{message}}
          </h1>
        </div>
      </div>
    </section>

  </body>
</html>

app.py


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

from bottle import Bottle, template, static_file, url
import os

app = Bottle()

@app.route('/static/:path#.+#', name='static')
def static(path):
    return static_file(path, root='static')

@app.route('/')
def index():
    message = "Hello, Bottle!"
    return template('index', message=message)

@app.error(404)
def error404(error):
    return "Error 404. Try again later."

@app.error(500)
def error500(error):
    return "Error 500. Try again later."

app.run(host='localhost', port=8080, debug=True)

When the generation is finished, go to the project folder and try running app.py.

$ cd <project-name>
$ python app.py

If you open http: // localhost: 8080, you should see something like the following.

(The display depends on the CSS framework you select.)

スクリーンショット 2020-02-11 15.48.34.png

All you have to do is write the code and enrich your project!

I think that there are many points that are not enough as a tool, but please use it if you like :)

Links

Bottle: https://bottlepy.org/docs/dev/index.html

Scaffolding tool: https://github.com/ShogoMurakami/create-bottle-app

Thanks, shogo

Recommended Posts

I made a scaffolding tool for the Python web framework Bottle
I made a python dictionary file for Neocomplete
I made a useful tool for Digital Ocean
I made a user management tool for Let's Chat
I made a login / logout process using Python Bottle.
I made a VM that runs OpenCV for Python
[Python] I made a classifier for irises [Machine learning]
I searched for the skills needed to become a web engineer in Python
I made a python text
I touched the latest automatic test tool "Playwright for Python"
[VSCode] I made a user snippet for Python print f-string
I made a Line-bot using Python!
I made a fortune with Python.
I made a daemon with Python
A memorandum of understanding for the Python package management tool ez_setup
Python> I made a test code for my own external file
I made a client / server CLI tool for WebSocket (like Netcat for WebSocket)
I made a lot of files for RDP connection with Python
I made a Python wrapper library for docomo image recognition API.
Introducing the BOT framework Minette for Python
I made a dash docset for Holoviews
I made a payroll program in Python!
I made a character counter with Python
[Python] A quick web application with Bottle!
A tool for easily entering Python code
I made a Hex map with Python
Let's make a web framework with Python! (1)
I made a browser automatic stamping tool.
After studying Python3, I made a Slackbot
I created a password tool in Python.
I made a roguelike game with Python
I tried benchmarking a web application framework
Let's make a web framework with Python! (2)
I made a simple blackjack with Python
I tried the Python Tornado Testing Framework
I made a configuration file with Python
I made a library for actuarial science
I made a WEB application with Django
A textbook for beginners made by Python beginners
I made a neuron simulator with Python
I made a Docker container to use JUMAN ++, KNP, python (for pyKNP).
I made a tool to automatically browse multiple sites with Selenium (Python)
I made a web application in Python that converts Markdown to HTML
Hit a method of a class instance with the Python Bottle Web API
I made a tool that makes decompression a little easier with CLI (Python3)
I made a program to check the size of a file in Python
I made a function to see the movement of a two-dimensional array (Python)
[Python] I tried substituting the function name for the function name
I made a weather forecast bot-like with Python.
Created a Python wrapper for the Qiita API
vprof --I tried using the profiler for Python
I made a spare2 cheaper algorithm for uWSGI
I made a GUI application with Python + PyQt5
I made a Twitter fujoshi blocker with Python ①
Procedure for creating a LineBot made with Python
[Python] I made a Youtube Downloader with Tkinter.
I tried python programming for the first time.
Python: Prepare a serializer for the class instance:
[Python] I searched for the longest Pokemon Shiritori
I made a downloader for word distributed expression
I made a LINE Bot with Serverless Framework!