🧬 μDjango (micro Django)
A single file Django micro project created for demonstration purposes to be used in the same way as other Python frameworks.
🏛️ History
I created this code while working on an improvement to Will Vincent's Django Microframework repository, which was itself inspired by a talk that Carlton Gibson gave at DjangoCon US 2019: "Using Django as a Micro-Framework".
Starting from that demonstration code I thought of a Django
micro application that could be used in the same way as a minimal application used in other Python
frameworks such as Flask
or FastAPI
.
I presented this code during the first sprint day of DjangoCon US 2023, together with Will Vincent and seeing the appreciation I decided to publish it in this repository.
μDjango presentation during the DjangoCon US 2023 sprints in Durham, North Carolina
💻 Set Up
⚗️ Virtualenv
Creating and activating the virtual environment:
$ python3 -m venv .venv
$ source .venv/bin/activate
🧩 Requirements
Installing the required python packages in the virtual environments:
$ python3 -m pip install django uvicorn
🧮 Code
Create a new file called udjango.py
and update it as follows:
from django import conf, http, urls
from django.core.handlers.asgi import ASGIHandler
conf.settings.configure(ALLOWED_HOSTS="*", ROOT_URLCONF=__name__)
app = ASGIHandler()
async def root(request):
return http.JsonResponse({"message": "Hello World"})
urlpatterns = [urls.path("", root)]
🏃 Run
Start the server with uvicorn
command.
$ uvicorn udjango:app --reload
🔬 Check it
Open your browser at http://127.0.0.1:8000
You will see the JSON response as:
{ "message": "Hello World" }
⚠️ Disclaimer
This code is for demonstration purposes only and should not be used in production. However, the code is released without any guarantee from the author and no liability can be attributed. Use at your own risk.
💬 Sharing
Here's where the μDjango (micro Django) project was shared online in case you want to re-share it.
🦣 Mastodon
📣 Django forum
⚖️ License
μDjango is licensed under the BSD 3-Clause License.
👥 Authors
👤 Paolo Melchiorre
- 🌍 Blog: www.paulox.net
- 🐙 Github: @[email protected]
- 🦣 Mastodon: @[email protected]
- 🐦️ Twitter: @[email protected]