# routes/admin/post.py

from sanic import Sanic
from controllers.admin.post import Post
 
app = Sanic.get_app('Multinews')
instance = Post()
 
@app.get("/admin/post")
async def getItem(req):
    return await instance.getItem(req)

 

# controllers/admin/post.py

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

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


    async def getItem(self,req):
        self.config["pageTitle"] = 'ទំព័រ​ការផ្សាយ'
        self.config['route'] = '/admin/post'
        self.config['type'] = 'post'

        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' %}
        {% elif(data['route'] == '/login') %}
            {% include './front/login.html' %}
        {% elif('/admin' in data['route']) %}
            {% include './admin/index.html' %}
        {% endif %}
    </body>
</html>

 

<!--templates/admin/index.html-->

Admin Index Page

 

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

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