Originally released as django-flasky, this is another django-in-a-single-file project - but it supports models, admin, and can automatically convert it into a full project.
Example:
from django.db import models
from nanodjango import Django
app = Django(ADMIN_URL="admin/")
@app.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>"
Save that as counter.py, then set up your database and run it locally with:
nanodjango counter.py run makemigrations counter
nanodjango counter.py run migrate
nanodjango counter.py run createsuperuser
nanodjango counter.py run
Run it in production using WSGI:
gunicorn -w 4 counter:app
or automatically convert it to a full Django app:
nanodjango counter.py convert /path/to/site --name=myproject