Live data from Hacker News

Django Newbie Mistakes

code.djangoproject.com

81–90 of 225 posts

Re: Django Newbie Mistakes

#81
Maybe not just Newbies, but I often notice even seasoned Django developers cribbing about Django's Class Based Views (CBV). I don't really understand why to be honest. There are many blog posts that express regretting the time invested in CBV by their respective authors by pointing out all sorts of pitfalls they fell into during usage. My ex-boss hates it as well, he even banned it from usage among developers. IMHO, it's was a great new introduction in version 1.3.

I hear them discuss about the difficulties and time it takes to implement some views which involves complex logic and more than one entity per view. How to embed a Form inside a Paginated page for example: to use a FormView or to use a ListView or both, followed by a long day of trying to exit a maze full of dead-ends

My advice to Newbies and other people who are struggling with CBV is:

1: You are probably not struggling with the concept of class based views.. just with Django's generic views module

2: Stop stressing about not being able to understand what each Django generic view class does, or it's Mixin classes. Instead refer to ccbv.co.uk and source code extensively - not just the docs.

3: If you are not able to fit every logic you want to fit inside your view using a generic Django view class.. Then just spin up your own class from Mixins or django-braces like nice apps or from object.

4: Remember, one basic upgrade you get from using Classes vs Functions is the ability to extend. If your views can not take advantage of this then you probably don't need a class based view, function based is fine. I almost always keep a base view class with me, often call it a ContextMixin(object) and use it in every view so that i can have some common context variables available in my every template.

Re: Django Newbie Mistakes

#82

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 ...

> React+Redux paired with an API

For building a REST API, there are no frameworks or languages I know of that are easier, quicker, or more user-friendly than Django REST Framework. I say this of someone who is not a big fan of Django in general (although it's not a bad framework).

However, I wish that Django REST Framework were build on top of an async HTTP server. Although it's never been an issue, I've occasionally in the past felt uneasy building APIs on top of Django since I know beyond a certain point scaling will be an issue. But either fortunately or unfortunately, I've never had that problem.

Re: Django Newbie Mistakes

#83
post #36

One of the things that makes me sad is there is no project even remotely close comparable to Django for say Golang or Scala. I love the fact that you get an admin interface out of the box. And tons of documentation. The views/template stuff is a bit dated since everyone started moving to frontend/backend services and SPAs but we still have DRF which is incredible in the amount you get for "free". I've had the "pleasu…

Indeed we are also looking for a framework to change our Django/python. We were looking at golang as half of our backend is in go but the lack of ORM make the choice impossibile. Gorm, xorm.. are not supporting Foreign Key...

Yes you can write your raw SQL query but that means that your backend can't support MySQL and Postgresql (one of our prerequisites for on-premise deployment).

So we are ending with phoenix. Very sad that golang doesn't provide a very good ORM.

Re: Django Newbie Mistakes

#84

Earlier quoted context omitted.

Scala / Play Framework does in fact have an out of the box solution for this: https://www.playframework.com/documentation/1.2.2/crud Edit: This was removed in Play Framework 2

They dropped that in Play 2.x, as far as I can tell.

Looks like you're right. Comment withdrawn.

Re: Django Newbie Mistakes

#85
post #81

Maybe not just Newbies, but I often notice even seasoned Django developers cribbing about Django's Class Based Views (CBV). I don't really understand why to be honest. There are many blog posts that express regretting the time invested in CBV by their respective authors by pointing out all sorts of pitfalls they fell into during usage. My ex-boss hates it as well, he even banned it from usage among developers. IMHO,…

Or just don’t use class based views. Simple function views do the job just as well while not obscuring code “behind a magic wall”.

Re: Django Newbie Mistakes

#86
post #83
post #36

One of the things that makes me sad is there is no project even remotely close comparable to Django for say Golang or Scala. I love the fact that you get an admin interface out of the box. And tons of documentation. The views/template stuff is a bit dated since everyone started moving to frontend/backend services and SPAs but we still have DRF which is incredible in the amount you get for "free". I've had the "pleasu…

Indeed we are also looking for a framework to change our Django/python. We were looking at golang as half of our backend is in go but the lack of ORM make the choice impossibile. Gorm, xorm.. are not supporting Foreign Key... Yes you can write your raw SQL query but that means that your backend can't support MySQL and Postgresql (one of our prerequisites for on-premise deployment). So we are ending with phoenix. Very…

What’s the motivation for moving away from python?

Re: Django Newbie Mistakes

#87
post #36

One of the things that makes me sad is there is no project even remotely close comparable to Django for say Golang or Scala. I love the fact that you get an admin interface out of the box. And tons of documentation. The views/template stuff is a bit dated since everyone started moving to frontend/backend services and SPAs but we still have DRF which is incredible in the amount you get for "free". I've had the "pleasu…

what made me sad when trying Django was that it felt not remotely close to RubyOnRails. Did I miss some ORM magic, scaffolds, generators, migrations? Did they add those in the meantime?

Love the admin interface and logic though, and python>ruby IMHO

Re: Django Newbie Mistakes

#88
post #36

One of the things that makes me sad is there is no project even remotely close comparable to Django for say Golang or Scala. I love the fact that you get an admin interface out of the box. And tons of documentation. The views/template stuff is a bit dated since everyone started moving to frontend/backend services and SPAs but we still have DRF which is incredible in the amount you get for "free". I've had the "pleasu…

what made me sad when trying Django was that it felt not remotely close to RubyOnRails. Did I miss some ORM magic, scaffolds, generators, migrations? Did they add those in the meantime? Love the admin interface and logic though, and python>ruby IMHO

What was the last version of Django that you used? There's build-in schema migrations since 1.7 version. Not sure what you mean by ORM magic.

Re: Django Newbie Mistakes

#89
post #36

One of the things that makes me sad is there is no project even remotely close comparable to Django for say Golang or Scala. I love the fact that you get an admin interface out of the box. And tons of documentation. The views/template stuff is a bit dated since everyone started moving to frontend/backend services and SPAs but we still have DRF which is incredible in the amount you get for "free". I've had the "pleasu…

> no project even remotely close comparable to Django for say Golang

I've used Django, flask and Golang quite a bit. One thing the Golang community seems to do a good job with is building things around the http.HandlerFunc interface which in turn leads to many of the subcomponents from other OS projects fit well together through chaining handlers. For example check out the Gorilla toolkit.

Django hides much of it away from you and the magic can be annoying at times. Flask seems to have failed on being both modular and nice to use for bigger projects (this is likely because WSGI isn't conducive to that sort of chaining).

Basically, with go I feel like I get Flask level lightness and visibility with actual modularity -- "easy to add batteries" if you will.

But I generally agree, Django is awesome. And the Django Admin is a whole beast of its own that is very unique and has been very useful for small staff alliances and management operations.

Re: Django Newbie Mistakes

#90
post #36

One of the things that makes me sad is there is no project even remotely close comparable to Django for say Golang or Scala. I love the fact that you get an admin interface out of the box. And tons of documentation. The views/template stuff is a bit dated since everyone started moving to frontend/backend services and SPAs but we still have DRF which is incredible in the amount you get for "free". I've had the "pleasu…

I've used neither, but Qor looks like it's of the same family: https://github.com/qor/qor
Post reply on HN