radiac / nanodjango

Full Django in a single file - views, models, API ,with async support. Automatically convert it to a full project.
573 stars 25 forks source link

Add static site support #36

Open radiac opened 1 month ago

radiac commented 1 month ago

Add a command to build a static site from your script.

I don't want to overload nanodjango with the kitchen sink, but this feels like a very useful feature - I've got several small static sites which I really wanted some of Django's features for, but setting up a full Django project felt overkill. A nanodjango script with a couple of models and some templates would have been perfect.

Probably should depend on #35

Usage: nanodjango <new_command> script.py /path/to/site. Possible command name:

Possible libraries to base it on, in order of github star popularity:

It looks like some of these packages will also deploy to s3 etc. That'd be a pretty handy feature, but I'm not keen on adding two commands for this. If supported, it would be better as eg nanodjango staticsite s3://...

It may also be good to have a --watch option - but only if there's a significant difference to nanodjango run

One other common use case would be to be running nanodjango serve on a private url, and have changes automatically trigger a build to a public one. That would be a nice feature, but I suspect out of scope - probably best handled with a HOWTO in the docs (touch a file, watch a file?)

Unless anyone has further suggestions, this will be pip install nanodjango[staticsite], nanodjango staticsite <script> <path>, and be based on django-distill, or django-freeze if we run into problems with distill

radiac commented 3 weeks ago

Thinking about this more, this may make more sense as a separate project. It's definitely something I still want, but it feels like more of an edge case than mainstream, and I'm trying to be mindful of not letting nanodjango get too fat (see #35). It may require an extension of the convert plugin system, or swapping to pluggy.

It could still be installed as a dependency with nanodjango[staticsite], but I'm not sure about it as that would mean installing it with nanodjango[all]. I'm thinking about the learning journey someone's going to go on - once they land on the docs page about creating a static site, it's just as easy to say "now pip install something-else" as it is "I hope you installed with pip install nanodjango[all]"

An additional thought - one of the big problems with this idea is needing to commit the database. Alex Kerney pointed out the yamldl project, which may be a good solution.