DEV Community

Cover image for TV Channel Website: Route to Dashboard
Sokhavuth TIN
Sokhavuth TIN

Posted on

TV Channel Website: Route to Dashboard

GitHub: https://github.com/Sokhavuth/TV-Channel
Vercel: https://khmerweb-tv-channel.vercel.app/login

To be able to build a dashboard, we need to define a route to that page first. This route will be linked to the Post class in the controllers section that in turn will be linked to the views section.

# index.py

from bottle import static_file, get
from routes.frontend import index
from routes.frontend import login
from routes.backend import admin


app = index.app
app.mount("/login", login.app)
app.mount("/admin", admin.app)

@app.get('/static/<filepath:path>')
def staticFile(filepath):
    return static_file(filepath, root="public")


###################################################################
import socket
host = socket.getfqdn()    
addr = socket.gethostbyname(host)
if(addr == '127.0.1.1'):
    app.run(host='localhost', port=8000, debug=True, reloader=True)

###################################################################
Enter fullscreen mode Exit fullscreen mode
# routes/backend/admin.py

from bottle import Bottle


app = Bottle()

from . import post
app.mount("/post", post.app)
Enter fullscreen mode Exit fullscreen mode
# routes/backend/post.py

from bottle import Bottle, get
from controllers.backend.post import Post


app = Bottle()
post = Post()

@app.get("/")
def getPage():
    return post.getPage()
Enter fullscreen mode Exit fullscreen mode
# controllers/backend/post.py

import config, copy
from bottle import template, redirect, request

class Post:
    def __init__(self):
        self.setup = copy.deepcopy(config.settings())


    def getPage(self):
        self.setup["pageTitle"] = "Post Page"
        self.setup["route"] = "/admin/post"

        return template("base", data=self.setup)


Enter fullscreen mode Exit fullscreen mode

Top comments (0)