Aurelia + Django boilerplate or tutorial?


#1

Is anyone here using Aurelia with Django? I would be grateful if anyone would point me towards a boilerplate project or tutorial showing how to build apps with Aurelia and Django.

There are enough differences between Rails, .net, etc. that it is hard for me to apply those patterns to the Django framework.


#2

I have a Django app where I plan on rewriting the front-end with Aurelia. Basically I look at Django and Aurelia as two different worlds. You don’t need to worry about Django templates at all. Your Aurelia app is just static and talks to your Django APIs. So you could use Django Rest Framework or graphene-django (GraphQL) for your backend and Aurelia for your frontend.

That said, if you just want to throw aurelia in here and there into an existing django app, I’ve read there is a way to augment your site with aurelia, but I haven’t been able to get it to work yet. It seems to be easier to augment a page with angular 1 or vue.js from my experience.


#3

I’ve managed to include an Aurelia application “inside” a Django project: It works like a charm!
Just add your bundle in templates/index.html

<body aurelia-app="main">
    <script src="{% static 'js/vendor-bundle.js' %}" data-main="aurelia-bootstrapper"></script>
</body>

If you don’t like the Django Template Language you can even remove it totally from your app and do everything using the Aurelia routing, i18n and fetch.

Since they are two separate projects they live in two different directories, so you have to write a task to copy your bundles from the Aurelia scripts directory to the Django static/js directory.
If you created the Aurelia project from the CLI (RequireJS, Gulp) you can change the path of your app-bundle.js from aurelia.json:

"targets": [
  {
    "id": "web",
    "displayName": "Web",
    "output": "scripts",
    "index": "index.html",
    "baseDir": ".",
    "useAbsolutePath": true,
    "baseUrl": "/static/js"
  }
],

You also want to make sure the paths of your assets (fonts, locale, etc.) match the static directory.
You can also build your Aurelia application to be used “outside” the Django project with little changes (e.g. to consume the Django API from a different URI).

By the way, I’m using Django REST Framework, otherwise wouldn’t make so much sense to use a full-fledged client-side web framework.
I suggest matching the Aurelia routing with the API endpoints, whenever possible, to be consistent between the two sides.

I haven’t run my project in production yet so I can’t tell about performances but Aurelia and Django match really well and are a pleasure to code at the point you feel guilty.