You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
tl;dr: I would like to import ninja before settings.DEBUG is available, so I can build a Django API in a single file. Are you open to a PR to address this?
I'm the author of nanodjango, a project to write a full Django project in a single file (views, models, admin etc), and then automatically convert it into a normal project structure once it has grown. I'm aiming to make a Flask or FastAPI alternative, with the power and scalability of Django.
A key piece of this is supporting django-ninja - I love the syntax and think they fit really well together. For example, this is a working single-file django project with a model, admin, standard view and a ninja api:
from django.db import models
from nanodjango import Django
django = Django()
from ninja import NinjaAPI
api = NinjaAPI()
@django.admin
class CountLog(models.Model):
timestamp = models.DateTimeField(auto_now_add=True)
@api.get("/add")
def add(request):
CountLog.objects.create()
django.route("api/", include=api.urls)
@django.route("/")
def index(request):
return f"<p>Number of API calls: {CountLog.objects.count()}</p>"
But you'll notice I've run into a problem with import order - django-ninja is testing settings.DEBUG on import (1, 2), but I have no way to configure django's settings until after nanodjango initialises, so I have to import it after that.
I'd really like to make it so that import order doesn't matter, so they can go together naturally at the top of the file and follow pep8.
Would you be open to me submitting a change to ninja.utils.is_debug_server to catch when settings aren't initialised and defer collection until settings are ready? I wouldn't change normal usage, just aim to allow people to import ninja at an unexpected
time.
The text was updated successfully, but these errors were encountered:
tl;dr: I would like to import ninja before
settings.DEBUG
is available, so I can build a Django API in a single file. Are you open to a PR to address this?I'm the author of nanodjango, a project to write a full Django project in a single file (views, models, admin etc), and then automatically convert it into a normal project structure once it has grown. I'm aiming to make a Flask or FastAPI alternative, with the power and scalability of Django.
A key piece of this is supporting django-ninja - I love the syntax and think they fit really well together. For example, this is a working single-file django project with a model, admin, standard view and a ninja api:
But you'll notice I've run into a problem with import order - django-ninja is testing
settings.DEBUG
on import (1, 2), but I have no way to configure django's settings until after nanodjango initialises, so I have to import it after that.I'd really like to make it so that import order doesn't matter, so they can go together naturally at the top of the file and follow pep8.
Would you be open to me submitting a change to
ninja.utils.is_debug_server
to catch when settings aren't initialised and defer collection until settings are ready? I wouldn't change normal usage, just aim to allow people to import ninja at an unexpectedtime.
The text was updated successfully, but these errors were encountered: