7 ms·
Building a full Django project, starting with a single file
- deleted 2y ago[deleted]
- simonw 2y agoI'm a big fan of the single-file Django ambition - it's the feature I most envy from frameworks like Flask and Starlette. I actually had a go at this myself 15 years ago, with a project I called Djng: https://github.com/simonw/djng https://github.com/simonw/djng - more details on that here: https://simonwillison.net/2009/May/19/djng/ https://simonwillison.net/2009/May/19/djng/
- BeefySwain 2y agoI would be interested to hear your thoughts on why this never ended up going anywhere? (Or did it go somewhere ?) As a Django user that shares your frustrations with settings.py, I wish this had panned out.
- simonw 2y agoI got very busy at work, then quit to go on honeymoon, then accidentally started a startup! I wasn't particularly good at sticking with open source projects like this and pushing them forwards back in 2009. I've since learned how to do that but it took me another decade to get there.
- BeefySwain 2y agoIs this something you think you would ever come back to?
- simonw 2y agoHonestly no - not at this point. I have too many other projects on the go. I'd love to see the Django community take this on generally - there are a bunch of people interested in it, hopefully that result in a long-term stable project around the idea.
- radiac 2y agoMe too, I'm convinced it has a place - the number of single file projects over the past few years can't be a coincidence. For me the two missing pieces were models and a path to migrate to a full project once it outgrew a single file, so I wrote nanodjango (https://github.com/radiac/nanodjango/ https://github.com/radiac/nanodjango/, formerly django-flasky) - you can use the ORM and admin site, and I recently added a "convert" command to automatically break up a single page app into a full Django project structure. I've been using it for a couple of years for prototyping/experimenting and putting together small apps, and with the new features this year feels like it's a really practical alternative to flask.
- pjerem 2y agoThis looks amazing ! Bravo
- radiac 2y agoThank you, it's great to have positive feedback!
- selcuka 2y agoThis looks really cool, congratulations. Are you planning to add some kind of API serving functionality (either by integrating something like Django Ninja or even raw Pydantic)? I think such single file frameworks are great candidates to implement microservices.
- radiac 2y agoThanks! Yes definitely, I think it's a great fit for anything self-contained and limited scope that doesn't need a lot of code. I've certainly found having an easy way to run a single file using Django's ORM is pretty handy. Regarding API serving, I'm planning on making it easier to use third party apps; the main obstacle is registering `includes` urls, which is doable at the moment but involves manually appending a path to `nanodjango.urls.urlpatterns`. I want to expand route registration to give a nicer internal api, then once that's in place Django Ninja should work pretty much out of the box - the only different should be how you register the url.
- Onavo 2y agoThe most powerful part of Django is its ORM, nothing else comes close in the ecosystem. The automatic migration generation tools for SQLAlchemy like alembic are much harder to use than django's built-ins. Django just needs to add Pydantic integration.
- axit 2y agoThere are couple of projects aiming to integrate django & pydantic: https://django-ninja.dev https://django-ninja.dev for APIs & https://github.com/jordaneremieff/djantic https://github.com/jordaneremieff/djantic for model data
- jdnier 2y agoWow, django-ninja is just what I was looking for. Thanks for pointing it out. Here’s their CRUD example: https://django-ninja.dev/tutorial/other/crud/ https://django-ninja.dev/tutorial/other/crud/
- jamestimmins 2y agoFew things I want more than for someone to extract the Django ORM from Django so we can use it standalone instead of SQLAlchemy
- boxed 2y agoYou can just use it though. There is no need to extract it.
- Onavo 2y agoThe migrations commands and configs are all tied to manage.py, hard to use without setting up the full boilerplate.
- boxed 2y agoIt's not really tied to manage.py no. And in any case that's a trivial 3 lines of code (plus imports, blank lines: https://github.com/iommirocks/iommi/blob/master/examples/manage.py https://github.com/iommirocks/iommi/blob/master/examples/man...). I think you're overdramatizing 3 lines of code...
- whatever1 2y agoI really love Django. I knew nothing about web development, it took me by the hand and from a tutorial I went to a full fledged application. I cannot fathom what is the GDP impact that these folks enabled.
- rossant 2y agoAfter more than a decade building custom admin-like interfaces from scratch in PHP, the auto-generated admin interface in Django felt like magic.
- SCUSKU 2y agoDjango admin + the Django ORM are the biggest reasons I haven’t moved to JavaScript Metaframework land. Next.js is great in its support of react and server rendered react for SEO. But where Django wins is that logic will always have to be on the trusted compute environment, the server. JS Metaframeworks approached the full stack problem from the front end and Django from the backend.
- sireat 2y agoFantastic idea to start Django with a single file! Some years back when I had to do some quick and dirty projects, I chose to go with Flask because of how dirt simple it was to start. All the Django books and tutorials had this hidden magic abstraction feel to them after: $ django-admin startproject <project-name> . $ python manage.py startapp <app-name> Once you've reinvented half the Django functionality in Flask (using SQLAlchemy etc) you realize the need for the most of these abstractions.
- wilsonfiifi 2y agoLightweight Django (2014) [0] actually explores using the Django framework in a similar manner. [0] https://www.oreilly.com/library/view/lightweight-django/9781491946275/ https://www.oreilly.com/library/view/lightweight-django/9781...
- seper8 2y agoAm I missing something or is there no sample code...?
- vldo 2y agoit's a series: - part 2: https://www.mostlypython.com/django-from-first-principles-part-2/ https://www.mostlypython.com/django-from-first-principles-pa... - part 3: https://www.mostlypython.com/django-from-first-principles-part-3/ https://www.mostlypython.com/django-from-first-principles-pa... also here's the repo: https://github.com/ehmatthes/django-first-principles/ https://github.com/ehmatthes/django-first-principles/
- deleted 2y ago[deleted]
- thedeparted_one 2y agoAwesome!
- xcdzvyn 2y agoI really wish there were something like this for Phoenix. I want to like it, but I feel a little inundated with all the codegen.
- agos 2y agoI second the feeling. It's really hard to tell what is (are?) the entry point and where does the flow go
- arcanemachiner 2y agoIf you use all the `--no-` flags (e.g. `--no-tailwind`) when creating a Phoenix project, you will be left with a surprisingly small amount of code. This is not so useful in a real project, but good as a learning exercises to see what comprises the core of a Phoenix application. https://hexdocs.pm/phoenix/Mix.Tasks.Phx.New.html https://hexdocs.pm/phoenix/Mix.Tasks.Phx.New.html FWIW, everything starts in your project's `lib/project/application.ex` file. All the things in the `start` function dictate the "flow" of the application.
- deleted 2y ago[deleted]
- jarpineh 2y agoI'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...
- japhyr 2y agoThe 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 https://github.com/radiac/nanodjango django-singlefile: https://github.com/andrewgodwin/django-singlefile https://github.com/andrewgodwin/django-singlefile