TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Django and Postgres for the Busy Rails Developer

180 pointsby plaur7825 months ago

10 comments

pmontra5 months ago
I&#x27;m working on a Rails and on a Django project for two different customers and I&#x27;ve been doing that for years now. I&#x27;d pick Rails over Django any time for every single feature.<p>The absolute worst Django feature is the templating language. It seems to be designed to slow down developers to the like of old time Java web apps, almost mandatory templatetags et all.<p>The query language is moderately bad, quite verbose (Model.objects every time) for no good reason.<p>The lack of common project structure means that every project is different.<p>There is no Capistrano to deploy. I wrote something like that myself and we have been using it for maybe 7 years.<p>I&#x27;m sure I could go on for a while if I keep thinking about it, but you got the gist of it.<p>On the Rails side, sometimes I&#x27;d like to have a talk with some of the previous developers of the Rails app, which hid some important functionality in a before save callback in a different module for no particular reason, but one can be too clever with Python too. However the language (Python) is quite dull, which can be a good or a bad thing. It&#x27;s very subjective. It&#x27;s a Ruby gone bad at design time to me.
评论 #42394664 未加载
评论 #42394684 未加载
评论 #42391149 未加载
评论 #42391065 未加载
评论 #42391429 未加载
评论 #42392348 未加载
评论 #42394470 未加载
评论 #42392570 未加载
评论 #42390925 未加载
评论 #42390484 未加载
评论 #42394460 未加载
评论 #42396687 未加载
评论 #42390901 未加载
评论 #42392531 未加载
评论 #42394490 未加载
评论 #42392652 未加载
评论 #42390971 未加载
评论 #42391157 未加载
Supernaut5 months ago
As a longtime Rails developer who has experimented with Python but knew little about Django, I read this article with interest. Something that jumped out at me was the author&#x27;s description of the &quot;models.py file, which contains all the application models (multiple models in a single file)&quot;. I did some quick research and I gather that this approach isn&#x27;t maintained as you move beyond the scale of a toy application. I kind of think he&#x27;s doing Django a disservice with his current wording there, as my immediate reaction was that it sounded nightmarish!
评论 #42390785 未加载
评论 #42390425 未加载
评论 #42393398 未加载
davidkwast5 months ago
Well. I use GeoDjango with PostGIS. Django supports it natively. And django-rest-framework takes it to another level.<p>Python has the best machine learning and AI support too. It is very easy to mix geographic libs with data science tools.<p>To build a simple CRUD software with vanilla SQL you really don&#x27;t need Django and Python. But I challenge any one to try a GIS full stack without Django and Python.<p>Just look for GDAL, pyproj, shapelly, fiona and MapLibre&#x2F;Mapbox.<p>And it really powerful to combine with HTMX or Vuejs for reactive SPAs
评论 #42395972 未加载
czhu125 months ago
I worked significantly in both Django and Rails, and I found the most magical part of rails is its ORM (ActiveRecord). I find both SQLAlchemy and DjangoORM both more awkward and less natural to use, both for the query side and the relationship definition side.<p>Once the data is loaded into memory, everything else is just syntax.<p>At this point, I only reach for python as a web application if I need to build something that has AI &#x2F; ML features. Rails apps I&#x27;ve built in the past that needed to call a local model resulted in having to create a python inference microservice, which kinda sucks.
评论 #42392547 未加载
sroerick5 months ago
I’ve spent a lot of time with Django, and not a lot of time with rails.<p>For me, if I was doing minimalist CRUD and wanted to ship to mobile or a lot of users, I’d reach for Rails. Hotwire and Turbo seem great, and the ecosystem just seems better and more developed for customer facing stuff.<p>Most of my work has been internal tooling with an emphasis on data analytics or geospatial. Having python libs run natively is a big win for data analysis, and as another commenter posted, geodjango is very tough to beat for usability for geospatial work. For this I still maintain Django is pretty unbeatable.<p>I am happy to be corrected in both domains though, again, not much rails experience here beyond a couple toy projects.
评论 #42397291 未加载
kitsune_5 months ago
I have yet to see a software project where ActiveRecordish ORMs did not end up making the modelling of business processes and translation of use cases into code overly messy and complicated, Rails or Django.
评论 #42392489 未加载
评论 #42392496 未加载
wfleming5 months ago
&gt; Migrations in Django &gt; &gt; The Django approach has noteworthy differences and a slightly different workflow<p>My explanation of Django&#x27;s approach to migrations would involve a lot more expletives. It is by far my least favorite thing about the framework.<p>- Fields are not-null by default, the opposite of SQL itself<p>- Field declarations use argument names that <i>sound</i> like the SQL equivalents (default, on delete cascade&#x2F;restrict), but they&#x27;re fully enforced in python and don&#x27;t make it into the SQL schema at all by default. I get that not every DB supports these features, and there are sometimes good reasons for doing something like a delete cascade in process (if you need to implement custom on-delete logic or something), but the DSL shouldn&#x27;t read like SQL if it&#x27;s not going to change the SQL schema. The default value thing combined with not-null by default is particularly easy to get bitten by adding a new field with default if you deploy migrations separately from deploying code (which you must do to avoid downtime): if you add a new field with a default value believing it&#x27;s safe, you will probably get crashes in the interval between applying the migration &amp; the new code deploying because you&#x27;ve got not-null column without a default value in the schema. They did finally add db_default recently, thankfully, but it took years!<p>- Django migrations cannot be understood in isolation, the sql a generated migration containing something like an AlterField operation will run depends on what <i>earlier</i> migrations say. You have to check with the sqlmigrate command and&#x2F;or actually read earlier migrations to be sure you understand what the migration will do. Compared to Rails, where each migration can be read and understood in isolation (though you may still need to understand how a Rails migration DSL will translate to actual SQL of course). This also has a performance impact making Django migrations slower because Django has an in-memory model of what the schema should be at each migration point, so running a migration is not just &quot;load the file and run the commands&quot;, it&#x27;s &quot;determine the schema that should exist after running this migration, diff that with the schema we think exists before this point, magically generate SQL for that diff, then run that&quot;.<p>- The makemigrations command to auto-generate pending migrations is very aggressive and will detect things as &quot;changed&quot; that don&#x27;t impact the schema. If you changed some help text on a field, or a localization string, or the aforementioned only-in-python default value, makemigrations will see that as requiring a migration that does nothing. Leads to lots of cruft.<p>- Related to both of the above points, AlterField&#x27;s auto-generated SQL can be dangerous and bad. Particularly, I&#x27;ve seen cases where very minor changes to a ForeignKey (like changing from nullable to not-nullable, or even not-schema-impacting changes like above) would, by default, have dropped the foreign key constraint &amp; index, and then re-created them. Completely unnecessary and potentially dangerous since it could be locking a large table. I&#x27;m not positive, but in some cases I think these have been generated purely because of a django upgrade leading to it deciding the names of the indexes&#x2F;constraints need to be changed for some reason.<p>- AlterField will <i>also</i> tend to stomp all over any tweaks you manually made to the schema to work around all these issues. If you manually wrote a SQL statement in an earlier migration to add a default value to a column, and then that column&#x27;s definition gets tweaked months or years later the generated AlterField is gonna remove your default value. At a technical level this isn&#x27;t surprising when you understand how Django is modeling the schema internally &amp; generating the SQL changes, but it&#x27;s definitely a bad user experience downstream of a lot of these design decisions.<p>Generally the field declaration&#x2F;migrations system in Django feels to me designed to lead people down a garden path towards bad and dangerous behavior. If I had my druthers I&#x27;d enforce a policy in our Django app of &quot;never run makemigrations, all migrations must be manually written SQL&quot;.
评论 #42392336 未加载
评论 #42398590 未加载
评论 #42397274 未加载
评论 #42393023 未加载
brap5 months ago
With all of this praise Rails is getting, even still in 2024, it’s mind boggling how there was never a successful Rails alternative in one of today’s popular web programming languages. Nothing ever caught on.
评论 #42393431 未加载
评论 #42407764 未加载
ltbarcly35 months ago
Django is a framework made of several components:<p><pre><code> - ORM: bizarre and can&#x27;t generate lots of common SQL you will want to generate. Weird joins via counting underscores. Horrible errors that don&#x27;t make sense. Lots of builtin functions have never worked and they won&#x27;t fix them. (ROUND has never worked!) - Template language: Slow and borderline unusable. are 50 pages of recursive nonsense tracebacks that doesn&#x27;t tell you anything usable. - Web app (controller) framework: Terrible and inflexible </code></pre> Each of these components is a piece of shit. Don&#x27;t use Django.<p>I suggest:<p><pre><code> - ORM: Sqlalchemy: probably one of the best ORMs in any language, good performance and very flexible. It won&#x27;t get in your way much. - Templates: jinja2: basically identical to django templates but faster and usable tracebacks are perfect - Web app: Flask or werkzeug, but there are lots of good options here. Django is the worst.</code></pre>
评论 #42397543 未加载
block_dagger5 months ago
I think Rails would be better off with TOML vs YML but otherwise I think Rails is better. Disclaimer: I’ve built dozens of Rails apps but never a full Django app. I dislike significant whitespace.