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.

Perfect for experiments, prototypes, tutorials, and small 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(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

It will create your database in a db.sqlite3 file next to your counter.py, with the appropriate migrations in migrations/.

Run it in production using WSGI:

gunicorn -w 4 counter:app

or automatically convert it to a full Django project:

nanodjango counter.py convert /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.4.0.tar.gz (17.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nanodjango-0.4.0-py3-none-any.whl (20.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for nanodjango-0.4.0.tar.gz
Algorithm Hash digest
SHA256 62f43eff4c8005842c0a08933a82e1621362676863fce3a871de05bf3bf1af0d
MD5 457a6d99932acfd646ec37a4837a9950
BLAKE2b-256 cb4d5acedfe1c8b1dce4623a6fa9714b8effe9ca269a819d8b7be180403337bf

See more details on using hashes here.

File details

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

File metadata

  • Download URL: nanodjango-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 20.0 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.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 73f7c68ae1f48d89207e01a5a1b231558a3c5c9ae1ca0c204ecdb173beb4ee87
MD5 39ff0a9a724c28ab898215a5ebf2bedc
BLAKE2b-256 1117522e64017f2300f9a3c2d1d2821ce80540cd48bf7ff005bac7b124c397eb

See more details on using hashes here.

Supported by

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