Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to split Python views in bottle.py

Tags:

python

bottle

I currently have a big file server.py containing all my bottle functions for routing. My application could be divided into 3 applications: news, forum, and blog.

I would know there is a good way to split my big file into 4 parts: news functions, forum functions, blog functions and common utilities (decorators, text formatting and others).

My current approach is to split my functions into 5 files : server.py, blog.py, admin.py, news.py and utils.py. server.py just contains the bottle.run() and import all others views.

Is it the good way? Is there any way to load/import functions automatically WITHOUT an import *.

like image 788
Augustin Laville Avatar asked Jun 01 '26 12:06

Augustin Laville


1 Answers

from blog import blogRoute
from admin import adminRoute
from news import newsRoute
from utils import utilsRoute
botapp = bottle.app()
for approute in (blogRoute, adminRoute, newsRoute, utilsRoute):
    botapp.merge(approute)

And in each of your python files, you just need this at the top: blog.py for example

from bottle import Bottle
blogRoute = Bottle()
like image 144
eatmeimadanish Avatar answered Jun 04 '26 02:06

eatmeimadanish