bottle
bottle copied to clipboard
[DeprecationWarning] Absolute template path names are deprecated
Hello.
- Python: 3.6.4
- Bottle: 0.12.13
I'm using Pipenv for manage virtual envs.
Code
# run.py
# Import Python packages
import os, json, bottle
from bottle import run, response, static_file
from bottle import jinja2_template as template
# Import Bottle Extensions
from bottle_sqlalchemy import SQLAlchemyPlugin
# Import SQLAlchemy
from sqlalchemy import create_engine, Column, Integer, String, Text
from sqlalchemy.ext.declarative import declarative_base
# Define dirs
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_DIR = os.path.join(BASE_DIR, 'static')
# App Config
bottle.TEMPLATE_PATH.insert(0, os.path.join(BASE_DIR, 'templates'))
bottle.debug(True) # Don't forget switch this to `False` on production!
# SQLite Database config
Base = declarative_base()
db_engine = create_engine('sqlite:///' + os.path.join(BASE_DIR, 'articles.db'))
# Starting App
app = bottle.default_app()
# Install Bottle plugins
app.install(SQLAlchemyPlugin(db_engine, keyword='sqlite_db'))
# Articles Database class
class ArticlesDB(Base):
__tablename__ = 'articles'
id = Column(Integer, primary_key=True)
title = Column(String(255), nullable=False)
description = Column(Text())
# API routes
@app.get('/api/articles/')
def get_all_articles(sqlite_db):
"""Get all Articles from Database"""
articles = []
articles_query = sqlite_db.query(ArticlesDB).all()
for i in articles_query:
articles.append({
'title': i.title,
'description': i.description
})
response.headers['Content-Type'] = 'application/json'
return json.dumps({'data': articles})
# Index page route
@app.get('/')
def show_index():
"""Show Index page"""
return template('index')
# Static files route
@app.get('/static/<filename:path>')
def get_static_files(filename):
"""Get Static files"""
return static_file(filename, root=STATIC_DIR)
# Run server
run(app, server='auto', host='localhost', port=8080, reloader=True)
Error
127.0.0.1 - - [16/Jan/2018 12:48:28] "GET /api/articles/ HTTP/1.1" 200 255
/Users/username/.local/share/virtualenvs/bottle-demo--x_uE0XF/lib/python3.6/site-packages/bottle.py:3335:
DeprecationWarning: Absolute template path names are deprecated.
fname = self.search(name, self.lookup)
On 3335 line of bottle.py (in my fresh env), I have functionloader
:
...
def loader(self, name):
fname = self.search(name, self.lookup) # <-- this line is 3335
if not fname: return
with open(fname, "rb") as f:
return f.read().decode(self.encoding)
...
But in this repository line 3335 have not similar function. Will be nice to push new version of Bottle to stable branch 👍