Live data from Hacker News

Django 4.1

djangoproject.com

81–90 of 126 posts

Re: Django 4.1

#81
post #8

If anyone is interested I updated my example Django Docker app to 4.1 at: https://github.com/nickjj/docker-django-example It includes running Django, Celery, gunicorn, Postgres, Redis, esbuild and Tailwind through Docker and Docker Compose. It's set up for development and production.

> CMD ["gunicorn", "-c", "python:config.gunicorn", "config.wsgi"]

Looks like this example is still WSGI?

Re: Django 4.1

#82

Earlier quoted context omitted.

Yes, it is just being put on a thread. A future Django release will use async database drivers. Django is very incrementally adding support for async. I don't believe they have started work on async templates yet, which will be one of the last major areas before the framework is fully async.

Why do they need Async templates? When a template renders it should be pure data and fully on the CPU. It seems Async templates would encourage a bad behavior of doing n+1 queries inside the HTML.

Django makes a lot of use of lazy evaluation. You'll often construct a QuerySet object in a Django view like this:

    entries = Entry.objects.filter(
        category="python"
    ).order_by("-created")[:10]
Then pass that to a template which does this:

    {% for entry in entries %}...
Django doesn't actually execute the SQL query until the template starts looping through it.

Async template rendering becomes necessary if you want the templates to be able to execute async SQL queries in this way.

Jinja has this feature already with the enable_async=True setting - I wrote a tiny bit about that in https://til.simonwillison.net/sqlite/related-content

Re: Django 4.1

#83

Earlier quoted context omitted.

No, I agree with you. It's 2022 and I have thought only once that it would be neat to have async methods from Django, but only as some 'cool thing to try'. I don't actually actually know if there would be any substantial benefit. It's like when I tried PyPy as my django interpreter. It gave a few percent speed increase in "real world" but created extra work for deployment. I've been using Django non-stop from 0.96, a…

> If I was running a trading clearing house, or Instagram, I'd probably care about marginal improvements, and then use another language. Ha, Instagram was written in Django!

Thats why I mentioned it, lol. I figured a few percentage points improvements in perf for Instagram == $$$

Re: Django 4.1

#84
post #81
post #8

If anyone is interested I updated my example Django Docker app to 4.1 at: https://github.com/nickjj/docker-django-example It includes running Django, Celery, gunicorn, Postgres, Redis, esbuild and Tailwind through Docker and Docker Compose. It's set up for development and production.

> CMD ["gunicorn", "-c", "python:config.gunicorn", "config.wsgi"] Looks like this example is still WSGI?

Yep but it includes "config.asgi" which you can use with gunicorn's uvicorn worker or uvicorn if you want if you want to use async views.

Re: Django 4.1

#85
post #8

If anyone is interested I updated my example Django Docker app to 4.1 at: https://github.com/nickjj/docker-django-example It includes running Django, Celery, gunicorn, Postgres, Redis, esbuild and Tailwind through Docker and Docker Compose. It's set up for development and production.

I was going to say you should offer a tutorial around how this can be used. It is much more useful to have a walk through when people put out such products. And then I decided not to say that because it is up to you how to spend your time and why should you make a tutorial for people if you don't want to. And then I realized, you have actually made dozens and this is the work you do. I think I took a Flask-docker cou…

Thanks a lot!

By the way the version of the course on Udemy doesn't get updated. The full version of the course is at https://buildasaasappwithflask.com/ which includes lifetime free updates (it has over 10+ hours of extra updates and new features not on the Udemy version). Udemy is a really bad platform for instructors which is why I've been trying hard to decouple myself from them over time.

As for a tutorial on using this repo specifically, did you find the readme file lacking in any way? I tried to write the readme to be fully self contained. It would expect prior Docker knowledge tho. I did give a talk at DockerCon going over a bunch of Docker best practices at https://nickjanetakis.com/blog/best-practices-around-product.... That talk live demos a Flask example app not Django but everything still applies to Django. The same patterns are used in both projects. It can act as a mini-tutorial on this repo.

Re: Django 4.1

#86
post #46

Earlier quoted context omitted.

I went with Django Rest Framework when I used it for a project because it provided things I would otherwise spend says implementing out of the box. The one thing I definitely did implement for myself was filtering, the built-in stuff was kind of mediocre for our needs, outside of that I want to say we left pagination and everything else as-is. It was a bit of a nightmare to look up documentation on though I will admi…

I remember watching a beautiful talk from some pycon whose details I can’t remember about using django as if it was a micro-framework. It basically boils down to rejecting the folder structure that django-admin sets up for you, importing stuff yourself and doing some basic initialisation/configuration. Once you do that, django kinda somehow behaves like a micro-framework, with the significant difference that you can…

I guess I prefer to keep it light and use a true microframework like flask for this use case. I find I can similarly import Flask extensions without bringing in a full heavy framework

Re: Django 4.1

#87
post #85

Earlier quoted context omitted.

I was going to say you should offer a tutorial around how this can be used. It is much more useful to have a walk through when people put out such products. And then I decided not to say that because it is up to you how to spend your time and why should you make a tutorial for people if you don't want to. And then I realized, you have actually made dozens and this is the work you do. I think I took a Flask-docker cou…

Thanks a lot! By the way the version of the course on Udemy doesn't get updated. The full version of the course is at https://buildasaasappwithflask.com/ which includes lifetime free updates (it has over 10+ hours of extra updates and new features not on the Udemy version). Udemy is a really bad platform for instructors which is why I've been trying hard to decouple myself from them over time. As for a tutorial on us…

I was going to say that you should really camelcase your url, because it's hard to see what it's saying, but even when you do that... https://buildASASSAppWithFlask.com/ doesn't really help that much hahaha.

Re: Django 4.1

#88
post #70

looking at the release notes and the source, it looks like the asyncio interface is still using the old drivers, like psycopg2 for postgresql, and using a threadpool. we at SQLAlchemy came up with a way to interface asyncio frontend and backend (like asyncpg for the driver) while maintaining all the "in the middle" code as synchronous style. the dark secret is that for this approach you have to use greenlet to propag…

thanks for sqlalchemy. it's a shining star in the Python package ecosystem.

> interface asyncio frontend and backend (like asyncpg for the driver) while maintaining all the "in the middle" code as synchronous style. the dark secret is that for this approach you have to use greenlet to propagate the "await" operations. It's been in our release for 18 months now with 1M downloads a day and there have been no problems reported with it, so i continue to wonder why nobody else seems to want to look at this approach.

do you have a blog post or some other kind of writeup to read about it? maybe nobody else had the same idea and it works so well nobody is aware that it can be done...

Re: Django 4.1

#89

Great to see improving support for async here. I am a big fan, but IMO python async code is just different from other async langauges. I used async extensively in python and compared to other languages it is a pain to use because unless 100% of the the libs you want support it you will get stuck on some sync library. Async in python is not even a 2nd class citizen. Its more like a 3rd class citizen. Its gets better e…

Yes, though I do think the python async ecosystem is gradually moving from a "3rd class citizen" to a "2nd class citizen". There are sync+async libraries like HTTPX that are gaining support. I don't expect it to really ever be a "1st class citizen" (supported as well as sync in pretty much every library everywhere) because of backward compatibility and ultimately async is just harder to program. Sometimes developer time is more important than the performance wins of async.

Re: Django 4.1

#90

Am I bad SWE if I do not care for for async in django? I am sure a a lot of django devs will like it, but if I need the performance that I would get from going async, I would not being using django as my web framework. FWIW I like django / python for a lot of things, just not for performance.

I don't care about it either. Who's actually doing a ton of querying in their views? We have materialized views for that.

I wish Django followed Ruby on Rails a little by focusing on improved developer experience instead of niche features that only a few mega corps need.

Post reply on HN