Web application with Python3.3.1 + Bottle (1) --Change template engine to jinja2

app.py


from bottle import route, run
from bottle import TEMPLATE_PATH, jinja2_template as template

TEMPLATE_PATH.append("./views")

@route('/')
@route('/hello/<name>')
def greet(name="Stranger"):
    return template('hello.j2', name=name)

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

The source is as above (development environment).

For your reference

hello.j2


{% extends "base.j2" %}

{% block content %}
    Hello {{ name }}! How are you?
{% endblock %}

base.j2


<html>
    <head>
        <title> Sample Bottle App </title>
    </head>
    <body>
        {% block content %} {% endblock %}
    </body>
</html>

Run the server on

% python app.py

http://localhost:8080/ When http://localhost:8080/hello/hoge When you access, you can see that the screen is output correctly with both defaults and parameters.

Recommended Posts

Web application with Python3.3.1 + Bottle (1) --Change template engine to jinja2
[Python] A quick web application with Bottle!
Jinja2 | Python template engine
Web application with Python + Flask ② ③
Web application with Python + Flask ④
Change Python 64bit environment to 32bit environment with Anaconda
Run a Python web application with Docker
Introduction to Tornado (1): Python web framework started with Tornado
Steps to develop a web application in Python
Explosive speed with Python (Bottle)! Web API development
[Introduction to Udemy Python3 + Application] 9. First, print with print
Template network config generation with Python and Jinja2
[ES Lab] I tried to develop a WEB application with Python and Flask ②
Web application using Bottle (1)
Python template engine empy
(Python) Try to develop a web application using Django
Change IP settings to ACL of conoha with python
Parse and visualize JSON (Web application ⑤ with Python + Flask)
Launch a Python web application with Nginx + Gunicorn with Docker
How to use template engine in pyramid 1 file application
Web application made with Python3.4 + Django (Part.1 Environment construction)
[No need to build local environment] Deploy Python bottle application made with Cloud9 to Heroku
Jinja2 | Python template engine
How to use Template Engine for Network Engineer
Use jinja2 template in excel file
How to use template engine in pyramid 1 file application
parse for format, for Jinja2 ...?
Python template engine empy
Web application with Python3.3.1 + Bottle (1) --Change template engine to jinja2
Use PySide for HDA UI
Pre-processing pipeline template for DataLiner
Python template for Codeforces-manual test-
Web scraping with python + JupyterLab
python3: How to use bottle (2)
How to convert an array to a dictionary with Python [Application]
BASIC authentication with Python bottle
Connect to Wikipedia with Python
Post to slack with Python 3
Web application development with Flask
[Python] Change dtype with pandas
[Part.2] Crawling with Python! Click the web page to move!
Web API with Python + Falcon
Switch python to 2.7 with alternatives
Write to csv with Python
How to change Python version
Search engine work with python
Save images on the web to Drive with Python (Colab)
Web scraping beginner with python
python3: How to use bottle (3)
Streamline web search with python
python3: How to use bottle
[Introduction to Udemy Python3 + Application] 51. Be careful with default arguments
Easy-to-understand explanation of Python Web application (Django) even for beginners (5) [Introduction to DB operation with Django shell]
If you know Python, you can make a web application with Django
Web application created with Python + Flask (using VScode) # 1-Virtual environment construction-
How to change Django's SQLite3 uploaded to python anywhere with GUI only
I tried to make a 2channel post notification application with Python
Move data to LDAP with python Change / Delete (Writer and Reader)
[Introduction to Udemy Python 3 + Application] 58. Lambda
[Introduction to Udemy Python 3 + Application] 31. Comments
Python: How to use async with
Link to get started with python
Web scraping with Python ① (Scraping prior knowledge)
[Python] Write to csv file with Python
Implemented file download with Python + Bottle
Create folders from '01' to '12' with python
Nice to meet you with python
[Introduction to Udemy Python 3 + Application] 57. Decorator
Try to operate Facebook with Python
Web application development memo in python