Skip to content

Commit

Permalink
Change run/start commands to manage/run
Browse files Browse the repository at this point in the history
refs #13
  • Loading branch information
radiac committed Sep 21, 2024
1 parent 8ae0e38 commit 8a63fe3
Show file tree
Hide file tree
Showing 17 changed files with 139 additions and 181 deletions.
33 changes: 22 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,14 @@ async def slow(request):
Save that as `counter.py`, then set it up and run it:

```sh
nanodjango start counter.py
nanodjango run counter.py
```

This will create migrations and a database, and run your project in development mode.

* See [Management commands](https://nanodjango.readthedocs.io/en/latest/management.html)
* See [Command usage](https://nanodjango.readthedocs.io/en/latest/usage.html)
for more options


### Convert it to a full site

If your project outgrows its single file, you can convert it into a full Django site:
Expand Down Expand Up @@ -92,16 +91,16 @@ and call `app.run()` at the bottom:

```python
if __name__ == "__main__":
app.start()
app.run()
```

Now your app can be run without installing anything, using `uv` or `pipx`:

```sh
# Run with uv
uv start ./script.py
uv run ./script.py
# or with pipx
pipx start ./script.py
pipx run ./script.py
```

You can still manually install dependencies and run the script directly with Python:
Expand All @@ -112,20 +111,32 @@ python script.py
```


### Run in production
### Run management commands

Anything you would normally do with `manage.py` you can do with `nanodjango manage`:
```sh
nanodjango manage script.py check
nanodjango manage script.py makemigrations script
nanodjango manage script.py runserver 0:8000
```

Run it in production using a WSGI server:

### Run in production

Run it using ``nanodjango serve``:
```sh
gunicorn -w 4 counter:app
nanodjango serve counter.py
```

or if you have async views, use an ASGI server:
This will use gunicorn, or uvicorn if you have async views.

Alternatively, you can pass the app directly to a WSGI or ASGI server if you prefer:
```sh
gunicorn -w 4 counter:app
uvicorn counter:app
```

* See [Command usage](https://nanodjango.readthedocs.io/en/latest/usage.html)
for more options

### Further reading

Expand Down
10 changes: 0 additions & 10 deletions docs/admin.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,6 @@ startproject`` template, so the admin site will always be enabled after conversi
using ``"admin/"`` if no models are decorated or if ``ADMIN_URL`` was not set.


Set up the database
===================

You will need to ``migrate`` before use, and you will want to add a superuser::

nanodjango run myapp.py migrate
nanodjango run myapp.py createsuperuser



Register a model
================

Expand Down
8 changes: 5 additions & 3 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ Features:

Breaking changes:

* Management command ``nanodjango run <script>`` no longer calls ``runserver`` by
default. Use ``nanodjango run <script> runserver`` or ``nanodjango start <script>``
instead.
* ``nanodjango run`` is now ``nanodjango manage``, mirroring ``manage.py``.
* ``nanodjango manage`` no longer calls ``runserver`` by default.
* ``nanodjango start`` is now ``nanodjango run``, differentiating it from ``serve``.
* ``Django.run()`` is now ``Django.manage()``
* ``Django.start()`` is now ``Django.run()``


0.8.1 - 2024-09-07
Expand Down
19 changes: 9 additions & 10 deletions docs/get_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,25 @@ Create a new file, ``counter.py`` with the following:
CountLog.objects.create()
return {"count": CountLog.objects.count()}
Now use the ``start`` command to create the migrations, apply them, and run your
Now use the ``run`` command to create the migrations, apply them, and run your
project:

.. code-block:: bash
nanodjango start counter.py
nanodjango run counter.py
or you could run each step manually:
or you could run each step manually using Django management commands:

.. code-block:: bash
nanodjango run counter.py makemigrations counter
nanodjango run counter.py migrate
nanodjango run counter.py createsuperuser
nanodjango run counter.py
nanodjango manage counter.py makemigrations counter
nanodjango manage counter.py migrate
nanodjango manage counter.py createsuperuser
nanodjango manage counter.py
Run it in production using WSGI:
Serve it in production using gunicorn:

.. code-block:: bash
gunicorn -w 4 counter:app
nanodjango serve counter.py
or automatically convert it to a full Django app:
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ Perfect for experiments, prototypes, tutorials, and small applications.
get_started
tutorial
settings
usage
views
api
admin
running
convert
convert_plugin
troubleshooting
Expand Down
6 changes: 0 additions & 6 deletions docs/requirements.in

This file was deleted.

58 changes: 5 additions & 53 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,54 +1,6 @@
#
# This file is autogenerated by pip-compile with Python 3.11
# by the following command:
#
# pip-compile
#
# Core build requirements
sphinx
-e git+https://github.com/radiac/sphinx_radiac_theme.git#egg=sphinx_radiac_theme
# via -r requirements.in
alabaster==0.7.16
# via sphinx
babel==2.14.0
# via sphinx
certifi==2024.2.2
# via requests
charset-normalizer==3.3.2
# via requests
docutils==0.17.1
# via
# sphinx
# sphinx-radiac-theme
idna==3.7
# via requests
imagesize==1.4.1
# via sphinx
jinja2==3.1.3
# via sphinx
markupsafe==2.1.5
# via jinja2
packaging==24.0
# via sphinx
pygments==2.17.2
# via sphinx
requests==2.31.0
# via sphinx
snowballstemmer==2.2.0
# via sphinx
sphinx==5.3.0
# via
# -r requirements.in
# sphinx-radiac-theme
sphinxcontrib-applehelp==1.0.8
# via sphinx
sphinxcontrib-devhelp==1.0.6
# via sphinx
sphinxcontrib-htmlhelp==2.0.5
# via sphinx
sphinxcontrib-jsmath==1.0.1
# via sphinx
sphinxcontrib-qthelp==1.0.7
# via sphinx
sphinxcontrib-serializinghtml==1.1.10
# via sphinx
urllib3==2.2.1
# via requests

# Optional
# sphinx-autobuild
4 changes: 4 additions & 0 deletions docs/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,7 @@ to configure itself and to simplify configuring Django:
``MIGRATIONS_DIR``
The directory name for migrations. Useful if you have more than one app script in the
same dir - such as the examples dir for this project.

``PUBLIC_DIR``
If set, nanodjango will use it to set ``WHITENOISE_ROOT``, so any files inside are
served from the site root. Useful for ``favicon.ico``, ``robots.txt`` etc.
2 changes: 2 additions & 0 deletions docs/troubleshooting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ we can fix this by moving the ninja import to after instantiating the ``Django``

from ninja import NinjaAPI # will fail here, settings are not configured
api = NinjaAPI()

In the specific case of ninja, you can use ``@app.api`` for convenience.
29 changes: 19 additions & 10 deletions docs/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,20 @@ file, and they must be defined after ``app = Django()``:
timestamp = models.DateTimeField(auto_now_add=True)
We can now create migrations for the app and apply them:
We can now run the script, which will create migrations for the app and apply them:

.. code-block:: bash
nanodjango run counter.py makemigrations counter
nanodjango run counter.py migrate
nanodjango run counter.py
You could also create migrations manually without running:

.. code-block:: bash
nanodjango manage counter.py makemigrations counter
For full details on how to use Django management commands with nanodjango, see
:doc:`management`.
:doc:`usage`.


Use the model
Expand Down Expand Up @@ -146,6 +151,8 @@ Use the admin site

To add a model to the admin site, decorate your models with the ``app.admin`` decorator:

.. code-block:: python
@app.admin
class CountLog(models.Model):
...
Expand Down Expand Up @@ -175,17 +182,19 @@ site to be active even if you're not using the decorator anywhere.::
Deploy to production
====================

The ``Django`` app instance supports WSGI, so for gunicorn it would be:
Nanodjango has a built-in command to run your script in production mode, with debug
turned off, using whitenoise, gunicorn or uvicorn, and sensible defaults::

.. code-block:: bash
nanodjango serve counter.py

gunicorn -w 4 counter:app
or for uwsgi:
If you want more control, you can also pass the ``Django`` instance to a WSGI or ASGI
server directly:

.. code-block:: bash
gunicorn -w 4 counter:app
uwsgi --wsgi-file counter.py --callable app --processes 4
uvicorn counter:app
Convert to a full Django project
Expand All @@ -198,7 +207,7 @@ You can do this with:

.. code-block:: bash
nanodjango counter.py convert /path/to/site --name=myproject
nanodjango convert counter.py /path/to/site --name=myproject
This will create a Django project at ``/path/to/site/myproject``, and unpack your single
file into a full app at ``/path/to/site/myproject/counter``. Your sqlite database,
Expand Down
Loading

0 comments on commit 8a63fe3

Please sign in to comment.