Posted Sep 17, 2023 at 4:22 PM
Edited Dec 17, 2024 at 8:25 PM
I had a list of features I wanted to have in place before I wrote my first blog post on this website. I’m happy to say that I’ve finally built those features and this is that post! I want to use this first post to talk about the technology behind this blog. I don’t think it’s anything super complex or groundbreaking or anything, but I had fun making it and want to talk about how it works.
This site is written almost entirely in Python using Sanic as my back-end framework. There’s also a grand total of 20 lines of JavaScript just to get a couple front-end features working, but otherwise that’s about it. I chose Sanic because we were using it for work and I wanted to get more familiar with it. Working with Sanic has been… fine. To me it feels a bit like Flask but just different enough to trip you up.
For example, in Flask url_for()
is just a function. You can import it and use it anywhere. In Sanic, however, url_for()
is a method of the app
class. This means that in order to use it you need to have an instance of app
handy. What this tends to look like for me is that I end up having a lot of request.app.url_for(...)
everywhere, because blueprints don’t just automatically have access to the app instance. This also means that in order to have links to other parts of the site in a way that doesn’t require me to go and update all my templates if I ever want to change a route, I need to pass the incoming request into the render function as context, which feels odd to me.
It’s just a lot of minor things like that everywhere that makes Sanic a little more awkward to use, but not crazily so. It’s still very usable and if you really need the speed it offers over something like Flask then I think it’s a fine choice.
Probably my favorite feature of this blog is the ability to write posts in Markdown. This was surprisingly (for me at least) easy to implement, both for the server-side rendering that you can see here and the front-end preview on the new post page that only I can see. On the back-end I’m using python-markdown and on the front-end I’m using this JavaScript library called Showdown. In both cases it’s as simple as passing the raw text into the appropriate library function and it spits out rendered HTML to just slap onto the page. It’s so simple, but it makes it super easy for me to make good looking blog posts.
I plan to add more features to this blog in the future, and when I do I’ll probably make posts talking about those too. For example, it might be good to add tags and a search function eventually. But for now this is the blog and I’m happy with it so far. I look forward to writing more posts here.
Bail wanted to be in the blog