# main.py
# pip install sanic[ext]

import os,time
from sanic import Sanic
from config import Config

os.environ['TZ'] = 'Asia/Phnom_Penh'
time.tzset()
 
app = Sanic('Multinews')
app.static("/static", "./static")
app.config.update(Config.config)
 
from routes.front import index

 

# config.py

class Config():
    config = {
        'siteTitle':'ពហុដំណឹង',
        'pageTitle':'',
        'message':'', 
    }

 

# routes/front/index.py

from sanic import Sanic
from controllers.front.index import Index
 
app = Sanic.get_app('Multinews')
 
@app.route("/")
async def index(req):
    instance = Index()
    return await instance.getItem(req)

 

# controllers/front/index.py

from sanic import Sanic
from sanic_ext import render
from copy import deepcopy

class Index():
    def __init__(self):
        app = Sanic.get_app('Multinews')
        self.config = deepcopy(app.config)

    async def getItem(self,req):
        self.config["pageTitle"] = 'ទំព័រ​ដើម'
        self.config['route'] = '/'
        self.config['message'] = 'កម្មវិធី​គេហទំព័រ​ ពហុដំណឹង កំពុង​រៀបចំ​បង្កើត!'

        return await render("base.html", context={"data":self.config})

 

<!--templates/base.html-->
<!--pip install Jinja2-->

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8"/>
        <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
        <title>{{data["siteTitle"]}} | {{data["pageTitle"]}}</title>
        <link href="/static/fonts/setup.css" rel="stylesheet">
        <link href="/static/styles/base.css" rel="stylesheet">
        <link href="/static/images/siteLogo.png" rel="icon" ></link>
        <script src="/static/scripts/jquery.js"></script>
    </head>
    <body>
        {% if(data['route'] == '/') %}
            {% include './front/home.html' %}
        {% endif %}
    </body>
</html>

 

<!--templates/front/home.html-->

{{data['message']}}

 

/* static/styles/base.css */

:root{
    --background: #c2c2c2;
    --background-dark: #fc096b;
    --background-light: lightgrey;
    --body-font: 14px/1.5 Vidaloka, OdorMeanChey;
    --link: teal;
    --color: #2c3444;
}
  
*{
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
a{
    text-decoration: none;
    color: var(--link);
}
a:hover{
    opacity: .7;
}
.region{
    max-width: 1150px;
    margin: 0 auto;
}
  
body{
    color: var(--color);
    font: var(--body-font);
    background: var(--background-light);
}

 

GitHub: https://github.com/Sokhavuth/khmerweb-multinews

Heroku: https://khmerweb-multinews.herokuapp.com