[HN Gopher] Portable Django
___________________________________________________________________
Portable Django
Author : ingenieroariel
Score : 54 points
Date : 2023-02-23 17:13 UTC (5 hours ago)
(HTM) web link (djngo.com)
(TXT) w3m dump (djngo.com)
| 0cf8612b2e1e wrote:
| This seems great. I do not have a clue as to what are the best
| ways to get a modern Python GUI app running, but I can absolutely
| slam together a Django application to make a web form. Hugely
| lower barrier to entry than trying to tackle Electron.
|
| Is it efficient or web scale? Probably not, but I will definitely
| consider this rather than say Gooey.
| robertlf wrote:
| Are people still using Django?
| ryanisnan wrote:
| Not to be condescending or patronizing, but, well, I'm
| answering your question and it itself has a dismissive tone.
|
| Yes, people are still using Django.
|
| As I've grown in my career, frameworks, libraries, and
| architectural patterns just become tools. I don't quite
| understand folks who identify as a "React developer", or a
| "Django developer". When evaluating any framework, you must
| learn to eschew the latest hotness long enough to evaluate what
| your requirements are, and maybe most importantly, what your
| constraints are.
|
| For a surprising amount of projects today, I would still
| recommend Django above anything else.
| JodieBenitez wrote:
| Are people still using a mature, stable, battle-tested
| framework with tons of third-party resources, great
| documentation and excellent coverage of many business needs ?
|
| Yes, of course.
| foobarbecue wrote:
| After a few years around the block (meteor, next.js), I'm back
| to Django. Got an mvp planetary web map annotation app up in no
| time, using Django DRF and just some plain hand-written js.
| Feels great to be back.
| jd3 wrote:
| I've seen this opinion on HN for years, but still don't
| _really_ understand it. Our cofounder built what is now a $1B+
| SaSS company from some cursory SQL knowledge he gained while
| interning at a hospital in the early 2010's. The entire
| business is, in essence, a fancy graphical UI around postgres.
|
| I've now been writing django at work for five years and still
| have yet to come across a query builder/orm which is as
| powerful yet simple in addition to being a breeze to on-board
| new engineers with.
|
| When there are queries that require the use of non-django
| builtins, it's also relatively easy to use django raw sql or
| just straight up use the psycopg2 sql.SQL dynamic string
| composition helpers.
|
| With the complexity of some our chained django QueryMethods,
| the company would have quite literally been impossible to build
| without django's query builder, at the very least.
| ryanisnan wrote:
| This is a double-edged sword in my opinion. The Django ORM is
| among my favourite ORMs, but the abstraction (like any) can
| cause problems over time.
|
| At scale, poorly understood ORM-generated queries can be a
| real pain, especially if your team's SQL skills have
| atrophied due to over-reliance on the ORM.
|
| As an exercise, I'd possibly recommend reviewing your top 1-3
| worst performing queries, tracking them back to the ORM, and
| evaluating how to improve them.
| axegon_ wrote:
| A lot. And it baffles me why hasn't anyone realized that
| Kenneth Reitz was right about django over a decade ago and all
| his points are equally valid today.
|
| https://speakerdeck.com/kennethreitz/flasky-goodness
| shanebellone wrote:
| Flask FTW.
| ingenieroariel wrote:
| If you like Flask (I do too), you can do what we used to do
| before Flask existed (./djngo.com -p project runserver)
| where .python/project.py in the zip is:
| import os from django.conf import settings from
| django.core import management from django.conf.urls
| import url from django.http import HttpResponse
| # Django 2.2 Release Notes #
| https://docs.djangoproject.com/en/4.1/releases/2.2/ #
| Documentation #
| https://docs.djangoproject.com/en/2.2/
| __version__ = 0.1 DEBUG = True
| ROOT_URLCONF = 'project' DATABASES = {'default': {
| 'ENGINE': 'django.db.backends.sqlite3', 'NAME':
| 'project.db' }} SECRET_KEY = os.getenv('SECRET_KEY',
| 'Please set a SECRET_KEY as an env var.') if not
| settings.configured: settings.configure(**locals())
| def index(request): return HttpResponse('Hello
| Django!') urlpatterns = [ url(r'^$',
| index), ] if __name__ == '__main__': #
| pragma: no cover
| management.execute_from_command_line()
| pbreit wrote:
| If not django, what on python? Anything else besides flask?
| iamsanteri wrote:
| Why?
| rytis wrote:
| > Just for fun
|
| It's mentioned right there
| iamsanteri wrote:
| Yeah I guess I understood that, but working in Django myself
| I don't quite get the point of it. Is it some older lighter
| version of Django and what for? I think this was more my
| point.
| ingenieroariel wrote:
| Author here. In 2007 when Django was starting to get
| popular there was a website called instantdjango.com where
| you could go and download a zip that would let you run
| Django and Python on Windows, with everything configured
| nicely.
|
| I only used that version because it is the official one
| supported by cosmopolitan, but it is also possible to use
| newer versions with the same approach, for example Python
| 3.11 and Django 4:
| https://github.com/ahgamut/cpython/tree/cosmo-djngo
| (Website has been updated to point at that one).
| dNIanGGER wrote:
| [dead]
| vandahm wrote:
| Why not?
| jart wrote:
| djngo.com is the culmination of years of effort, creating a
| single file python executable that runs on all platforms. This
| project is based on APE (https://justine.lol/ape.html) and in
| the past few days, our Python APE port (called python.com)
| became good enough to run Django. So we put Django inside the
| executable too, and called it djngo.com. The djngo.com
| executable will _just work_ on the following platforms:
|
| - Apple x86_64 and ARM64
|
| - Linux running x86_64 or ARM64 (Raspberry Pi)
|
| - Windows running x86_64 and possibly ARM64 too
|
| - FreeBSD, NetBSD, and OpenBSD running x86_64
|
| It does not require that Python be installed beforehand. It's a
| native Python executable. It does not require Rosetta or Qemu
| be installed either, in order to run ARM64 platforms. It does
| not require Cygwin or MSYS2 runtimes in order to run on WIN32.
| It only depends on KERNEL32. It has an embedded JIT VM called
| Blink (https://github.com/jart/blink) which it pulls out on
| non-x86 platforms to emulate itself. All its dependencies are
| bundled inside using a zip polyglot, including the Python
| standard library: unzip -vl djngo.com
| ... 5588 Defl:N 1707 70% 02-23-2023 16:06
| 26fb04f6 .python/django/shortcuts.py 0 Stored
| 0 0% 02-23-2023 16:05 00000000 .python/ctypes/ 34
| Stored 34 0% 02-23-2023 16:05 1b5bb9b2
| .python/ctypes/__init__.py -------- -------
| --- ------- 35075517
| 11728493 67% 7171 files
|
| You can put your app's assets inside the djngo.com file too,
| using the standard zip tool. You can then rename the file, and
| insert a `.args` file that supplies default args for launching
| your white-labeled app.
|
| This means that if you're a Django app developer, you can now
| easily share your apps with others wanting to run it locally.
| It's almost as easy for anyone on any platform to use, as if
| you productionized it onto a website. Rather than a hyperlink
| away, it's a single file download and CLI invocation away. You
| won't need to explain things like, "here's how you install
| Python on Windows" or "here's how you install Docker and setup
| a Linux distro, in order to run my app." Your users will be in
| full control of the app, granting maximum privacy and control
| over data, and zero operations toil for you!
| mushufasa wrote:
| Why Django 2.2? That version is no longer supported, and I'm
| guessing there's some technical reason you are using the
| obsolete version? (Production Django is now on major version
| 4)
| ingenieroariel wrote:
| The technical reason for choosing Python 3.6 no longer
| applies due to how quickly cosmo has advanced in the past
| months (in particular thread support). jart and ahgamut
| were the ones who made it happen, I am only a python.com
| user.
|
| But if you want Django 4 and Python 3.11, here is some info
| copied from the website:
|
| 3. Newer Python and newer Django? It is possible to have a
| djngo.com with Django 4 and Python 3.11. Solved by aghgamut
| who was the first to port Python to Cosmopolitan. Please
| note that this Python and the one that djngo.com use are
| different, the later has been heavily optimized by jart to
| run well on cosmo, the former is as close as upstream as
| you can get. Choose your destiny.
|
| curl -O https://djngo.com/djngo4-py311.com
| jart wrote:
| The cosmo monorepo currently vendors Python 3.6, since
| cosmo originally didn't have threads support and that was
| the last version before threads became mandatory. I'm
| pretty happy with the old version since I've been using
| Django since the 2000's. I put a lot of work into enhancing
| monorepo cosmo python with things like a better REPL that
| works across platforms. It may not be supported by the
| Python team, but it's supported by me. However the future
| will probably be building Python w/ Cosmo _outside_ the
| monorepo. See the other comments for details on how to use
| APE + Python 3.11 for a modern experience.
| [deleted]
| somethoughts wrote:
| Perhaps it could be an effort toward an implementation of
| Local-First Web Development. [1]
|
| [1] https://news.ycombinator.com/item?id=34857435
| leafmeal wrote:
| I'm getting the wrong hash when I download the file (I tried a
| couple times).
|
| I'm running curl -O https://djngo.com/djngo.com
| shasum -a 256 djngo.com
|
| and I get
| 6133a4f5c76af6ca6a2b2eba115783a78fc1721cd384539076884f640b801a26
| djngo.com
|
| I'm on a M1 Mac. Am I missing something obvious?
|
| I tried running it anyway (smart I know) and it failed with
| zsh: exec format error: ./djngo.com
| ingenieroariel wrote:
| Please try again, I just re-ran the deployment and tested on my
| M1 (OSX): x@m1n1n0 ~> chmod +x djngo.com
| x@m1n1n0 ~> sha256sum djngo.com
| 6205984f572575c407ce65502361b554af17584f076076bec7440613459d
| 1dff djngo.com x@m1n1n0 ~> ./djngo.com extracting
| blink-darwin-arm64 to /var/folders
| /fn/4cdpvwcx1wnc53rzl2m0pn_m0000gn/T//.ape-blink-0.9.2
| Python 3.6.14+ (Actually Portable Python) [GCC 9.2.0] on cosmo
| Type "help", "copyright", "credits" or "license" for more
| information. >>:
| [deleted]
| JazzXP wrote:
| What a missed opportunity in calling it Django Unchained
___________________________________________________________________
(page generated 2023-02-23 23:00 UTC)