Live data from Hacker News

Django Newbie Mistakes

code.djangoproject.com

151–160 of 225 posts

Re: Django Newbie Mistakes

#151

Earlier quoted context omitted.

Thanks... ? Having dates on the pages would probably help avoid some of this in the first place. People point to a lot of the PHP comments in their docs as "bad" (and many are) but they're also dated, and you can use a comment date of 2009 when trying to give weight to how relevant/useful something may be. "blank=..." anything is, imo, more confusing than "required=", regardless of what version/age of the docs though…

The issue is: what would you list as the date? Apparently some other people noticed this was on HN, too, so there are minor edits from a few hours ago, but the bulk of the information is still a decade old. Would you stick a date on every paragraph? (personally I'd forgotten that this page even existed)

"Created on" and "last modified".

I see last modified way at the bottom of a long page in light grey.

I did not even notice it was a wiki until others point it out.

Biggest text on the page says 'code'. I plead nav-blindness to not seeing 'wiki' in the floating navbar.

Perhaps a date on every block section?

Or... something that throws a big block at the top if the last edit was more than 2 years ago?

Re: Django Newbie Mistakes

#152

Django is great at being "batteries included," with tons of functionality for free. One thing that bugs me about these frameworks however is that you have to wire everything together by hand, sometimes from both sides. Would be great if there were a product built on top that let you drop a model or a view file in a folder and everything would be wired automatically for the default case, customizable later of course.

Django Rest Framework is getting close to that.

Huh?! Any moderately complex usage of DRF requires tons of boilerplate, or ton of app-specific abstractions... Also, just having to write a view, then a serializer... to actually write it!!

Imho the ideal framework would work with a models definition, json or yaml, not code, with extra anatotions for everything needed to have the logic of stuff like serializers and views instantiated from them. And keep the "custom behaviors" code fully separate from this models config, preferably in some modules with stateless and mostly pure function, sort of the serverless mindset, and not too much oop bullshit on top.

Rails and all the frameworks that copied it (Django, Laravel etc.) set a really bad example imho...

Re: Django Newbie Mistakes

#153
post #92
post #72

Earlier quoted context omitted.

> I've had the "pleasure" of working with other large projects built on flask and ever time it gets to a certain size I wonder why we didn't just use Django. Actually, I've had the exact opposite experience. I like using Django for small and mid-sized projects, because with Flask I have to spend time adding all these extra libraries for universally required functionality on a quick app whereas, with Django it's plug…

Similar experience for me. Django is pretty thick with quite a bit of (confusing, to me) magic. Flask comes without very basic components that are required for pretty much any website (user accounts, db access, etc).

Between Django and Flask, Pyramid is often forgotten. It seems like the only one of the three that has been genuinely designed to be extended (vs. Flask's approach of "here you have a magic-global variable (that's magically working like a stack of dicts), go put some stuff into it"); a good example would be renderers. In Django it's still kinda awkward to use other/multiple templating engines; Flask doesn't really help. Pyramid on the other hand has a simple and extensible interface to support multiple templates and other renderers ( https://docs.pylonsproject.org/projects/pyramid/en/latest/na... ). This is a common theme with Pyramid. Another is avoiding global state; they're quite successful at that (vs. "I declare my entire app/blueprint within a function"-Flask and "I don't know how this works, it's just like magic. I go to my model class and, BAM, suddenly I'm connected to some database"-Django).

(Other examples where the other two's solution feel rather lackluster to me include middleware vs. view derivers, view predicates, the routing system and the security area)

Re: Django Newbie Mistakes

#154
post #131

Earlier quoted context omitted.

“Validation defined on the model is only enforced on the form” hasn't been true since 2010 when Django 1.2 was released. Most of the database-related discussion shares that pattern of either being factually incorrect (“queries can't use computed columns”), blaming Django for MySQL's many problems or failing to fix problems caused by other code failing to do things like input validation. There's a real discussion abou…

You must not have read the section "Validation defined on the model is only enforced on the form". The validations I referenced, e.g. `choices`, are only run in when [`full_clean()`]( https://docs.djangoproject.com/en/dev/ref/models/instances/?... ) is called, and it's not called on `save()`--it is usually called through form validation. Regarding computed columns, it looks like the specific issue I ran into repeated…

> You must not have read the section "Validation defined on the model is only enforced on the form". The validations I referenced, e.g. `choices`, are only run in when [`full_clean()`](https://docs.djangoproject.com/en/dev/ref/models/instances/?...) is called, and it's not called on `save()`--it is usually called through form validation.

In addition to being wrong about whether I read your post, this is a great illustration of what I found tedious while reading it: since that feature was released in Django 1.2, the documentation has been clear about the relationship between save() and full_clean():

https://docs.djangoproject.com/en/2.0/releases/1.2/#model-va...

http://django.readthedocs.io/en/1.2.X/ref/models/instances.h...

The direct statement of fact you used as a heading simply hadn't been true for years before you wrote your post and it's not helped by little mocking asides such as “Because nobody ever modifies a model instance expect through its form, right?” which are basically restating the reasons why that feature exists in the first place.

> I should have been explicit that I was referring to not being able to define such computed columns on the model the way one would a normal column, not to being unable to use `F`-expressions.

Strong agreement here. Your post could have been so much more useful if each of the mocking asides had instead been taken as a cue to ask whether it's more likely that so many people have worked on Django for years without noticing such a major flaw or that your understanding of how it was intended to be used is incorrect.

Imagine if your post had been something like “Things I learned about Django the hard way” and had covered things like picking safer defaults or updating the docs to more explicitly suggest how validation is intended to work (especially in this age where people use fewer forms and more APIs than a decade ago), or that Django treats the database as the ultimate source of truth so you should approach various things about validation and transactions with that in mind (e.g. strengthening the the wording to make it clear that e.g. get_or_create relies on database integrity checks so you should either set those or religiously use some other strategy). That post could be a DjangoCon talk and it'd get a lot more positive reaction than another angry rant on an internet full of them, especially since people in the community would be likely to share it rather than seeing a big claim which is not correct and closing the tab.

Re: Django Newbie Mistakes

#155
post #92
post #72

Earlier quoted context omitted.

> I've had the "pleasure" of working with other large projects built on flask and ever time it gets to a certain size I wonder why we didn't just use Django. Actually, I've had the exact opposite experience. I like using Django for small and mid-sized projects, because with Flask I have to spend time adding all these extra libraries for universally required functionality on a quick app whereas, with Django it's plug…

Similar experience for me. Django is pretty thick with quite a bit of (confusing, to me) magic. Flask comes without very basic components that are required for pretty much any website (user accounts, db access, etc).

Maybe it's because I'm used to Rails, but there is really little magic in Django. One is even free to structure the code as one likes. Almost no mandatory directory structure. It's a beefier Flask but still straightforward. If I may come up with a criticism, there are too many complications that slow down development compared to Rails.

Re: Django Newbie Mistakes

#156

From my perspective there's little reason to be building html serving webservers these days. 1) Frontend React+Redux paired with an API (eg golang http server serving json) 2) Your boss is going to want "APIs!" soon anyways. le sigh. 3) IMO its as easy to do a JSON API HTTP server in golang as python, but you get typesafety, compiled code and multicore ...

But then in Goland most people are even against ORMs, so the difference in productivity becomes gigantic. Maybe the pragmatic way is to write a prototype in Django and rewrite in Go once the design stabilizes (I mean, for the smallish stuff I work on..)

Re: Django Newbie Mistakes

#157

Earlier quoted context omitted.

Personally, as a customer, the "new" way of doing it is irritating, usually somewhat broken, slow and usually unreliable. I wouldn't be surprised if non-techies couldn't give a toss if you're using a traditional MPA with a sprinkling of ajax for the bits that really need to be responsive or a total SPA. I'm beginning to suspect the only people who want a SPA are the programmers. Has anyone even got any proof that a S…

Good SPAs are fantastic . It's just a lot of people suck when implementing them. The Serverless documentation, an SPA, blew my mind in terms of how fast and clean it is: https://serverless.com/framework/docs/

It takes ~2.5 seconds to load and the first ~1.5 of that won't display anything because it has to process ~600KB of JavaScript and CSS before it can render a few hundred words of text:

http://www.webpagetest.org/result/180628_AQ_c87264f303f9e72f...

The only reason that's faster as an SPA than static HTML is because they've disabled caching for static resources:

http://www.webpagetest.org/result/180628_AQ_c87264f303f9e72f...

If the site was optimized it'd perform very similarly either way since there's none of the complex logic or interactions where an SPA really starts to shine and the content is very cache-friendly.

Re: Django Newbie Mistakes

#158
post #72

Earlier quoted context omitted.

> I've had the "pleasure" of working with other large projects built on flask and ever time it gets to a certain size I wonder why we didn't just use Django. Actually, I've had the exact opposite experience. I like using Django for small and mid-sized projects, because with Flask I have to spend time adding all these extra libraries for universally required functionality on a quick app whereas, with Django it's plug…

Agreed. Also, unless django has changed peaking under the hood is a nightmare. Forms and the ORM (and really the whole framework) is giant ball of mud.

Yep, forms smell of Java Struts. I was so happy to say goodbye to them when I started using Rails in 2006. Another Javism, templatetags, because they don't want we write Python in the templates. So every small customization takes x100 the time in the best tradition of early 2000 Java frameworks.

Re: Django Newbie Mistakes

#159

Earlier quoted context omitted.

Really ? Randomly clicking e.g. Providers > Azure, I see a significant loading animation (the grey lines) - likely slower than just loading a simple new page each time. (Compare e.g. https://docs.python.org/3/library/weakref.html. ) (Single Page Applications arguably have their place. I'm just really confused why you think this is a particularly good example.)

On my awful connection, serverless is as fast as HN on new pageloads, and faster than HN when navigating to cached pages. HN is my baseline for how fast a site should be.

HN is typically how I determine no connection vs. crap connection.

Re: Django Newbie Mistakes

#160

Earlier quoted context omitted.

Really ? Randomly clicking e.g. Providers > Azure, I see a significant loading animation (the grey lines) - likely slower than just loading a simple new page each time. (Compare e.g. https://docs.python.org/3/library/weakref.html. ) (Single Page Applications arguably have their place. I'm just really confused why you think this is a particularly good example.)

On my awful connection, serverless is as fast as HN on new pageloads, and faster than HN when navigating to cached pages. HN is my baseline for how fast a site should be.

HN is typically how I determine no connection vs. crap connection. I could `ping` I suppose, but in these circumstances I'm in the browser having just signed in to the crap/not connecting AP.
Post reply on HN