Metadata-Version: 2.1
Name: nanodjango
Version: 0.4.0
Summary: Run Django models and views from a single file, and convert it to a full project.
Author-email: Richard Terry <code@radiac.net>
Project-URL: Homepage, https://radiac.net/projects/nanodjango/
Project-URL: Documentation, https://nanodjango.readthedocs.io/en/latest/
Project-URL: Changelog, https://nanodjango.readthedocs.io/en/latest/changelog.html
Project-URL: Repository, https://github.com/radiac/nanodjango
Project-URL: Issues, https://github.com/radiac/nanodjango/issues
Keywords: django
Classifier: Development Status :: 4 - Beta
Classifier: Framework :: Django
Classifier: License :: OSI Approved :: BSD License
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Requires-Python: >=3.8
Description-Content-Type: text/markdown
Requires-Dist: black
Requires-Dist: click
Requires-Dist: Django>=3.2
Requires-Dist: isort

# nanodjango

[![PyPI](https://img.shields.io/pypi/v/nanodjango.svg)](https://pypi.org/project/nanodjango/)
[![Documentation](https://readthedocs.org/projects/nanodjango/badge/?version=latest)](https://nanodjango.readthedocs.io/en/latest/)
[![Tests](https://github.com/radiac/nanodjango/actions/workflows/ci.yml/badge.svg)](https://github.com/radiac/nanodjango/actions/workflows/ci.yml)
[![Coverage](https://codecov.io/gh/radiac/nanodjango/branch/main/graph/badge.svg?token=BCNM45T6GI)](https://codecov.io/gh/radiac/nanodjango)

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:

```sh
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:

```python

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:

```sh
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:

```sh
gunicorn -w 4 counter:app
```

or automatically convert it to a full Django project:

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

and with a [couple of extra
lines](https://nanodjango.readthedocs.io/en/latest/management.html#run-script), 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:

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

For more details, see

* [Getting started](https://nanodjango.readthedocs.io/en/latest/get_started.html)
* [Tutorial](https://nanodjango.readthedocs.io/en/latest/tutorial.html)
* [Full Documentation](https://nanodjango.readthedocs.io/en/latest/index.html)
* [Changelog](https://nanodjango.readthedocs.io/en/latest/changelog.html)
