Closed smlbiobot closed 7 years ago
Oh, whoops, I rewrote part of the file and completely forgot to re-add those items.
Give me a minute and I'll update the docs.
Wow thanks for the speedy reply! This is unexpected :)
If in the future you have time, I’d love some help on using jinja2 with it also but not a big issue as I know that is slightly off-topic for this library.
The docs will rebuild automatically and be live in about 10 minutes.
I can help you here, I guess, what's the issue?
No issue — mostly just want to see an example of it somewhere. Or you can perhaps link me to a public repo which uses both Kyuokai + jinja2 to see what’s the ideal way of setting both up?
As far as I know, there's no public repository.
However, the Asphalt usage tutorial + https://asphalt-templating.readthedocs.io/en/latest/ should be able to guide you.
Ah—very sweet! Thanks for the link!
Just being a bit intrusive here, but what I did to set it up was the following:
from asphalt.core import ContainerComponent, Context
from asphalt.templating.component import TemplatingComponent
from kyoukai.asphalt import KyoukaiComponent
from jinja2 import FileSystemLoader
from pathlib import Path
import kyoukai
app = kyoukai.Kyoukai('app')
class ApplicationComponent(ContainerComponent):
async def start(self, ctx: Context = None):
if not ctx:
ctx = Context()
self.add_component('templating', TemplatingComponent, backend='jinja2', searchpath=str(Path(__file__).parents[1]) + '/templates', loader_class=FileSystemLoader)
self.add_component('kyoukai', KyoukaiComponent, ip=SERVER_IP, port=SERVER_PORT, app=app)
await super().start(ctx)
endpoint = ApplicationComponent()
But it was returning an html as plain text instead of rendering it (jinja2 had processed it though), so where I was returning the html I used
return kyoukai.util.as_html(ctx.jinja2.render('anypage.html', var=var))
which basically just adds "Content-Type": "text/html"
to the response headers.
This is what worked for me.
First of all, thanks for creating this framework. I just downloaded it and am testing it out. Currently going through your docs here: https://mirai.veriny.tf/en/latest/core/gettingstarted.html
And while I thought that it’s nice that you be as brief as possible, may I suggest that you add the source for the entire file somewhere? I had to look up other people’s code using library to know that I have to add:
from kyoukai.util import as_html
app = Kyoukai("my_app_name")
in order to get the basics running. I know that it may seem obvious, but it is unclear from the doc itself that these are needed.