#!/usr/bin/env python
# -*- coding: utf-8 -*-
import click
from bottle import static_file, Bottle, run, Jinja2Template, TEMPLATE_PATH
from beaker.middleware import SessionMiddleware

from {{cookiecutter.app_name}} import settings
from {{cookiecutter.app_name}}.routes import Routes


TEMPLATE_PATH.insert(0, settings.TEMPLATE_PATH)
Jinja2Template.settings = {
    'extensions': ['jinja2.ext.autoescape'],
    'autoescape': True
}
session_opts = {
    'session.type': 'file',
    'session.auto': True
}

app = SessionMiddleware(Bottle(), session_opts)

# Bottle Routes
app.wrap_app.merge(Routes)


@app.wrap_app.route('/assets/<path:path>', name='assets')
def assets(path):
    yield static_file(path, root=settings.STATIC_PATH)


@click.group()
def cmds():
    pass


@cmds.command()
@click.option('--port', default=8080, type=int,
              help=u'Set application server port!')
@click.option('--ip', default='0.0.0.0', type=str,
              help=u'Set application server ip!')
@click.option('--debug', default=False,
              help=u'Set application server debug!')
def runserver(port, ip, debug):
    click.echo(u'Start server at: {}:{}'.format(ip, port))
    run(app=app, host=ip, port=port, debug=debug, reloader=debug)


if __name__ == "__main__":
    cmds()

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import click
from bottle import static_file, Bottle, run, TEMPLATE_PATH
from beaker.middleware import SessionMiddleware

from {{cookiecutter.app_name}} import settings
from {{cookiecutter.app_name}}.routes import Routes


TEMPLATE_PATH.insert(0, settings.TEMPLATE_PATH)
session_opts = {
    'session.type': 'file',
    'session.auto': True
}

app = SessionMiddleware(Bottle(), session_opts)

# Bottle Routes
app.wrap_app.merge(Routes)


@app.wrap_app.route('/assets/<path:path>', name='assets')
def assets(path):
    yield static_file(path, root=settings.STATIC_PATH)


@click.group()
def cmds():
    pass


@cmds.command()
@click.option('--port', default=8080, type=int,
              help=u'Set application server port!')
@click.option('--ip', default='0.0.0.0', type=str,
              help=u'Set application server ip!')
@click.option('--debug', default=False,
              help=u'Set application server debug!')
def runserver(port, ip, debug):
    click.echo(u'Start server at: {}:{}'.format(ip, port))
    run(app=app, host=ip, port=port, debug=debug, reloader=debug)


if __name__ == "__main__":
    cmds()

remove jinja2 settings