Run Django models and views from a single file, and convert it to a full project.
Maintained. Last release 3 days ago, commits in 6 of the last 26 weeks. Weaker on contributor spread.
pip install nanodjangonanodjango
- Write a Django site in a single file, using views, models and admin
- Run it locally or in production, or share it as a standalone script
- Automatically convert it to a full Django project when you're ready for it to grow
- Try it out in your browser at the nanodjango playground
Head to nanodjango.dev to get a high level overview of what nanodjango can do, or you may like to watch a lighting talk.
Quickstart
Install nanodjango:
pip install nanodjango
Write your app in single .py file - for example:
from django.db import models
from nanodjango import Django
app = Django()
@app.admin
class CountLog(models.Model):
# Standard Django model, registered with the admin site
timestamp = models.DateTimeField(auto_now_add=True)
@app.route("/")
def count(request):
# Standard Django function view, or class-based view
CountLog.objects.create()
return f"<p>Number of page loads: {CountLog.objects.count()}</p>"
@app.api.get("/add")
def add(request):
# Django Ninja API support built in
CountLog.objects.create()
return {"count": CountLog.objects.count()}
@app.route("/slow/")
async def slow(request):
import asyncio
await asyncio.sleep(10)
return "Async views supported"
Save that as counter.py, then set it up and run it:
nanodjango run counter.py
This will create migrations and a database, and run your project in development mode.
- See for more options