Skip to main content

Run Django models and views from a single file, and convert it to a full project.

Project description

nanodjango

PyPI Documentation Tests Coverage

Write a Django site in a single file, using views, models and admin, then automatically convert it to a full Django project when you're ready for it to grow.

An alternative to Flask (see example below) and FastAPI (see our django-ninja example) - similar simple syntax, but with full access to Django's features such as the ORM, auth and admin site.

Perfect for experiments, prototypes, sharing working code samples, and deploying small production applications.

Quickstart

Install nanodjango:

pip install nanodjango

Create a file counter.py using Django's standard features, and the @app.route and @app.admin decorators to tell nanodjango where your URLs, views and model admin are:

from django.db import models
from nanodjango import Django

app = Django()

@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 start counter.py

It will create your database in a db.sqlite3 file next to your counter.py, with the appropriate migrations in migrations/. Alternatively you could run each of these commands manually with the run command, eg nanodjango run counter.py runserver 0:8000

Run it in production using WSGI:

gunicorn -w 4 counter:app

or automatically convert it to a full Django project:

nanodjango convert counter.py /path/to/project --name=myproject

and with a couple of extra lines, run the development server as a standalone script using python, or use pipx run to run it and automatically install dependencies to a temporary virtual environment:

# Either
python script.py
# or
pipx run ./script.py

For more details, see

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nanodjango-0.6.0.tar.gz (23.5 kB view details)

Uploaded Source

Built Distribution

nanodjango-0.6.0-py3-none-any.whl (26.8 kB view details)

Uploaded Python 3

File details

Details for the file nanodjango-0.6.0.tar.gz.

File metadata

  • Download URL: nanodjango-0.6.0.tar.gz
  • Upload date:
  • Size: 23.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for nanodjango-0.6.0.tar.gz
Algorithm Hash digest
SHA256 2befb4aeab8b4d3c5e370c9dec55f5707b94d203c619e7681d4c8f259d2f83cc
MD5 36d08382b1a454e09040f9df1ce30e66
BLAKE2b-256 e56421637e27e36198563c565c2cf237733eb830ab111a1499ed9d72eb29904d

See more details on using hashes here.

File details

Details for the file nanodjango-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: nanodjango-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 26.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for nanodjango-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 09aab4275d07df06ad331de04be3a281dac311e1be752762cebc1d688b4d6c83
MD5 73a27865feca6a7b9dd3d8ba4c83683e
BLAKE2b-256 910720832c4392670c990cdc0bbb9422606e08efebec503391f9db35b386d18a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page