Email or username:

Password:

Forgot your password?
Simon Willison

I'm really impressed by nanodjango (by @radiac, presented in a lightning talk at #djangoconUS just now) - it's the latest in a long line of attempts to have Django work for Flask-style single file apps but it's got WAY more features than previous attempts I've seen, like model and admin support and even async

My notes here: simonwillison.net/2024/Sep/24/

nanodjango docs and tutorial: nanodjango.readthedocs.io/

4 comments
Simon Willison

The getting started fits in a single image

pip install nanodjango

Create a counter.py file:

from django.db import models
from nanodjango import Django

app = Django()

@app.admin # Registers with the Django admin
class CountLog(models.Model):
    timestamp = models.DateTimeField(auto_now_add=True)

@app.route("/")
def count(request):
    CountLog.objects.create()
    return f"<p>Number of page loads: {CountLog.objects.count()}</p>"

Then run it like this (it will run migrations and create a superuser as part of that first run):

nanodjango run counter.py
Tom Parslow

@simon I’ve been using this to experiment with data models for a new bit of a larger app without having to think about how it all fits in. It’s great!

Michael Morisy

@simon @radiac Oh that's awesome! Will have to kick the tires for the next project in that scope I try. Flask has been my default but this looks great.

markwalker

@simon @radiac I came across this a few weeks back. Really impressive package for throwing together ideas with the features to then expand into a fully fledged project if you need to.

Go Up