Hacker News new | past | comments | ask | show | jobs | submit login

I'd love to use Django as a fast and easy single file app. There's some great looking solutions here. Have to take a look.

I tried myself about five years ago. My idea was to make a tool that could make a HTTP service from any Python file with very simple setup. With all the features of Django at the ready. Unfortunately neither Django's configuration system nor Python import methods made it reliable enough. Or I just couldn't hack it. This was the smallest I managed:

  from django.urls import path
  from django.http import HttpResponse

  CONF = {
    "INSTALLED_APPS": ["serverless"],
    "ROOT_URLCONF": (path("", lambda x: HttpResponse("look ma, no server")),),
    "DEBUG": True,
    "SECRET_KEY": "randobrando"
  }
Other thing I tried to do with this was attach a Jupyter kernel. This way I could change the code as I went, but wouldn't have to use entire Jupyter client stuff. Unfortunately there I ran into problems with event loops. I could not find a way to manage different servers in the same runtime instance. Perhaps it's time to try again wiser and helped by LLMs...



The app-based model is really baked into Django. As we've seen from a bunch of examples, especially recently, it's not too hard to build out a single-file project that serves a simple home page with a brief message. As soon as you want to support a full actual page, and a set of pages, you really have to figure out a well-thought-out plan for how people will expand the project.

If you're still interested in this work, I suggest checking out nanodjango, which was mentioned earlier in this thread. That project is new, but there's a plan from the outset for how people can transition from the single-file based version to a standard Django project. You might also want to check out Andrew Godwin's django-singlefile project. It's meant to support small flask-like projects, where you don't have any intention of expanding out into a standard Django project.

Both of these projects have their own code that takes what's included in the small file and tells Django how to make sense of it. That's much different than the projects that are only trying to make use of what's included in Django itself.

(I'm the author of the Django from first principles series that was submitted here, but I didn't see it on HN until this morning.)

nanodjango: https://github.com/radiac/nanodjango

django-singlefile: https://github.com/andrewgodwin/django-singlefile


Thank you for your reply. For the first point, I agree. When I was doing my experiments with single file Django I was thinking of combining few simple, single purpose apps into one regular Django project. This project would serve as an actual site for people to use with its own templates, but hopefully not that much custom code. With ASGI coming along (this was 2019 I think) I even tried to combine these app pieces under one ASGI server. Sadly I run into some trouble with server tooling.

In regards to nanodjango I shall take a look. Also, need to read the rest of your articles. Thank you for writing them! Iā€™d still like to experiment with the idea of small, independent, pluggable apps. Perhaps Django can be coaxed to this now.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: