News for hackers. Stuff that matters.
Re:Django 2.1 released by fredley on Wednesday August 01, 2018 @11:22AM (#17663305)
I've been working with Django for almost my whole career, since 1.1. It's a joy to use, and blows any other web framework I've used out of the water when it comes to actually just building stuff.

Django is a fantastic boring[1] tool, and seeing boring updates like this is great.

1: http://mcfunley.com/choose-boring-technology

Re:Django 2.1 released by ergo14 on Wednesday August 01, 2018 @11:57AM (#17663700)
It is worth noting that Pyramid Web Framework is also awesome to use. I see it as a middle ground between Django and Flask. The scaffolds make some design decisions for project and you can pick from what you like the most. Pyramid allows for extensible applications and never gets in your way.

The most critical Python infrastructure (PyPi) is now built with it, if you haven't tried it give it a shot. It is one of most well thought out frameworks for python in my opinion.

I've made a tutorial for it: https://docs.pylonsproject.org/projects/pyramid-blogr/en/lat....

Re:Django 2.1 released by blumomo on Wednesday August 01, 2018 @01:30PM (#17664732)
I'm a very happy ist of Pyramid. Using it professionally for various larger applications as well as for pet projects.

It's very well thought through. We're providing a GraphQL and integrating it was a breeze.

Re:Django 2.1 released by audiolion on Wednesday August 01, 2018 @08:06PM (#17668207)
I would be interested to hear about how you did pyramid and graphql, ive been following graphene but are there specific tie ins for pyramid? books? articles?
Re:Django 2.1 released by blumomo on Sunday August 05, 2018 @08:20AM (#17690963)
The integration is actually straight forward if you use the "graphene" library which you already looked in to. If you use SQLAlchemy, there's even a graphene-sqlalchemy binding which makes it really really easy.

Simply add a /graphql view to your Pyramid app such as:

  from cornice import Service
  from pyramid.exceptions import HTTPBadRequest

  from ..schemas import schema


  graphql = Service(
      name='graphql',
      path='/graphql',
      description="GraphQL",
      accept='application/json',
      renderer='json',
  )


  @graphql.post(permission='readwrite')
  def post_graphql(request):
      query = request.json_body.get('query')
      variables = request.json_body.get('variables', None)
      if not query:
          raise HTTPBadRequest
      return schema.execute(query, variable_values=variables, context_value={
          'dbsession': request.dbsession,
          'user_id': request.authenticated_userid,
      })
Re:Django 2.1 released by OmarGonzalez on Wednesday August 01, 2018 @12:07PM (#17663801)
Django is a fantastic boring[1] tool, and seeing boring updates like this is great.

couldn't agree more

Re:Django 2.1 released by godzillabrennus on Wednesday August 01, 2018 @12:39PM (#17664177)
My roommate in College built a site with 0.96 of Django. It’s still running.

I think it’s one of if not the longest running commercial Django websites.

Re:Django 2.1 released by paganel on Wednesday August 01, 2018 @01:58PM (#17665074)
I have some personal websites that still run on Django 0.96. I also keep the source-code for them in svn and use Trac 0.12 (I think) for pretty-viewing the code in the repository. It’s nice seeing commits you made 11 or 12 years ago.
Re:Django 2.1 released by collinmanderson on Wednesday August 01, 2018 @01:29PM (#17664719)
I maintain a Django ecommerce site that's been running constantly since July 12, 2007 (at launch it was running against r4984, basically 0.96). Just upgraded it to 2.1 today.
Re:Django 2.1 released by chocolatkey on Thursday August 02, 2018 @03:19AM (#17669748)
Any struggle with the upgrade?
Re:Django 2.1 released by collinmanderson on Thursday August 02, 2018 @09:49AM (#17671324)
No struggle. I regularly develop and test it against Django master with loud warnings so I fix compatibility issues one at a time as they appear in Django master. I also don't use any 3rd party libraries which means I can upgrade right away.

In this cycle all I needed to tweak was something related to `use_required_attribute` on a form, and I did that back in March. I needed to add `renderer=None` to to my form field render() method, but I did that back when it was a warning in March 2017.

Re:Django 2.1 released by spacesarebetter on Wednesday August 01, 2018 @01:17PM (#17664569)
I have been using symfony since the 2-3 years because the product is build on symfony. Now i like symfony, because i’m not a big fan of PHP. Anybody knows how Django compares to Symfony. I have glanced through Django documentation few times and it look a little similiar. If somebody has used both frameworks, what are the main advantages of Django over Symfony?
Re:Django 2.1 released by nickserv on Wednesday August 01, 2018 @04:29PM (#17666681)
I use both, but we choose Django for all new projects. For advantages of Django vs Symfony, there's first advantages of Python over PHP...

In a web design context probably the biggest advantage is having things like asynchronous code where it makes sense and websockets without having to use another technology stack such as node.js.

Otherwise I simply find we are more productive using Django, it allows less boilerplate code for similar functionality, there is less complexity involved overall.

Disadvantage is maybe for really large projects with many developers, Symfony might be easier to have someone pick up the code since it's more standardized.

Re:Django 2.1 released by chipotle_coyote on Wednesday August 01, 2018 @04:24PM (#17666623)
While "it's in Python and not PHP" immediately comes to mind, a less snarky answer is that Django feels optimized for building bespoke content management systems. Take some time to play around with the automatic admin generation.
Re:Django 2.1 released by KyeRussell on Thursday August 02, 2018 @05:01AM (#17670144)
I understand that it's played out (both as a general discussion, and as replies to your post) but PHP's shortcomings as a language are so blatant when working with any other okay general purpose language.

Community also goes a long way. Back when I dealt in PHP (+whatever framework) and switched to Django, the average competence of people I interacted with in conversations regarding the language / frameworks jumped up considerably. I like standing on the shoulders of giants.

Re:Django 2.1 released by zimablue on Wednesday August 01, 2018 @12:09PM (#17663812)
As a counter point, I tried to use Django for a data-visualisation project and ran into some problems. Everything is built on models, which are kind of activerecord pattern. Django has an inbuilt (and inferior) version of sqlalchemy, so that when you want to push sql past a certain point (define queries more complex than the api) you're pretty much stuck. Now you have codebase with two different database libraries in it. You're probably using an spa so all the view stuff isn't helping, and Django kind of infects your code because it won't run without an initializarltion step so if you have a module importing something that imports Django, any time you use that it needs to initialize Django itself. I don't think that these are mistakes, just choices that they made that make it very good for websites up to a certain (sql/data) complexity and very annoying afterwards.
Re:Django 2.1 released by blattimwind on Wednesday August 01, 2018 @01:27PM (#17664691)
Pyramid is often forgotten. It's 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). Django ORM is awkward and not that good, but awkward to replace.
Re:Django 2.1 released by akx on Wednesday August 01, 2018 @12:12PM (#17663851)
The Django ORM has raw SQL escape hatches (either fully raw SQL database connections or model instance selections with SQL), and if you do need the SQLAlchemy query builder, slap in something like https://github.com/Deepwalker/aldjemy .

As for the initialization stuff -- yes, that's true; whenever Django models are being imported, you do need to have had `django.setup()` called.

Re:Django 2.1 released by zimablue on Wednesday August 01, 2018 @12:24PM (#17663989)
yea good point, I should have mentioned the raw SQL escape hatch, that also isn't an ideal solution. I went for aldjemy/instead them and in retrospect starting with something sqlalchemy native would have been cleaner.
Re:Django 2.1 released by c0un7d0wn on Wednesday August 01, 2018 @01:45PM (#17664918)
We went the other way around and came up with https://github.com/shosca/django-rest-witchcraft and https://github.com/shosca/django-sorcery to integrate sqlalchemy with django as the project was already using sqlalchemy.
Re:Django 2.1 released by kennydude on Wednesday August 01, 2018 @12:20PM (#17663947)
> Django kind of infects your code because it won't run without an initializarltion step

Most people using Django have built their apps as Django apps so this is a "non issue".

The worst way to use Django is to try and fight against the way it was built. For your case specifically, it's probably not a good option.

Re:Django 2.1 released by meric on Wednesday August 01, 2018 @12:15PM (#17663884)
You might have seen aldjemy already but I thought I might mention it https://github.com/Deepwalker/aldjemy - let's us use SQLAlchemy queries in our django code without requiring redefining the models in an SQLAlchemy manner. It's easy to put a wrapper around it to convert SQLAlchemy results back into Django model instances.

I'm exploring using Django Channels to send data to visualisation SPA's in realtime. https://channels.readthedocs.io/en/latest/

Re:Django 2.1 released by zimablue on Wednesday August 01, 2018 @12:18PM (#17663925)
Yep I'm using Aldjemy as a bridge for now and it works great. I still really don't like having two completely different db layers in the same codebase. Whilst we're plugging the ecosystem/extensions, I also use Alembic which is amazing.
Re:Django 2.1 released by andybak on Wednesday August 01, 2018 @01:48PM (#17664946)
> Django has an inbuilt (and inferior) version of sqlalchemy

Django has it's own ORM with a different design philosophy that is optimised for a different use-case to sqlalchemy.

Django's ORM is generally cleaner and more readable for the common case and requires less code to set up. It might be slightly less elegant for more complex cases but it's a trade off that's made me pretty happy on balance.

Re:Django 2.1 released by djsumdog on Wednesday August 01, 2018 @01:04PM (#17664441)
I mean that's a general problem with ALL ORMs. I've been on Django projects where we had to drop down and pass raw SQL statements.

On my current project we don't use an ORM; just SQL statements and we create classes to match the result set and map into them.

Re:Django 2.1 released by blattimwind on Wednesday August 01, 2018 @01:29PM (#17664713)
Disagree. It's mostly a question of whether the ORM was designed as a "least-common denominator of common operations supported by some RDBMSs" (which is clearly the case for the Django ORM) or as an abstraction of SQL concepts (i.e. a form of relational algebra). The former category generally fares poorly with complex queries or structures; the latter exceeds at them.
Re:Django 2.1 released by Serow225 on Wednesday August 01, 2018 @01:32PM (#17664768)
What are some good examples of the latter type of ORM? Thanks
Re:Django 2.1 released by blattimwind on Wednesday August 01, 2018 @01:35PM (#17664807)
sqlalchemy
Re:Django 2.1 released by OmarGonzalez on Wednesday August 01, 2018 @12:29PM (#17664058)
I don't disagree with your assessments of django limitations. It does however, seems like a poor choice for your specific problem.

This is why the problem inform the solution, pick the framework (or lack of) that suits your problem best

Re:Django 2.1 released by Humphrey on Thursday August 02, 2018 @07:59AM (#17670780)
Totally agree. I've been using Django since 0.96 and it's is so mature now. Earlier they introduced so many new features... but it's now a very mature framework that doesn't really need any new features.
Re:Django 2.1 released by blackrock on Wednesday August 01, 2018 @11:33AM (#17663432)
What do you use to write your front end Javascript?
Re:Django 2.1 released by johnthedebs on Wednesday August 01, 2018 @11:42AM (#17663529)
Not OP, but I've also been using Django for (more than) my whole career and I use React on the frontend.

If you're curious about the frontend path I took, it was roughly:

* jQuery with no framework

* Backbone (for a couple years)

* Backbone + Marionette (for a couple more years)

* Angular (for about a week)

* React (for the past few years)

Re:Django 2.1 released by oneweekwonder on Wednesday August 01, 2018 @12:08PM (#17663804)
When you moved to Angular and later to React did you have any jQuery heavy libraries?

I'm using stuff like slickgrid[0], jquery-ui datepicker, json-editor[1] and wonder how I will drive these components from something like Angular or React?

doh, quickly googled for the github links below and saw there now a slickgrid-es6[2] fork which I have not tried. But my question still stand: how do you drive jquery libs from newer frameworks?

[0]: https://github.com/6pac/SlickGrid/wiki

[1]: https://github.com/json-editor/json-editor

[2]: https://github.com/DimitarChristoff/slickgrid-es6

Re:Django 2.1 released by conradfr on Wednesday August 01, 2018 @12:21PM (#17663955)
I have encapsulated jQuery (including Bootstrap) plugins in AngularJS, React and Vue in the past. They all allow you to access a DOM node somehow.

Maybe it's frowned upon but I don't really like to use those (usually partial) Bootstrap re-implementation, especially in non-SPAs where you already have jQuery and/or Bootstrap.

Of course it's becoming less and less necessary.

Re:Django 2.1 released by johnthedebs on Thursday August 02, 2018 @12:50AM (#17669294)
Other users have already commented, but basically you can wrap jQuery libraries in React components and do a bit of extra work in the lifecycle methods (componentDidMount, componentWillUnmount, etc.) to manage the jQuery bits.

Once you've wrapped it in a component, you can more or less drop that component anywhere in your view hierarchy and not have to think about the fact that it's using jQuery under the hood.

This highlights one of my favorite things about React and similar frameworks, which is that it's the closest thing to actual, useful encapsulation of components I've seen in a frontend framework. It's not perfect, but it's much better than everything I used before it.

Re:Django 2.1 released by always_good on Wednesday August 01, 2018 @01:14PM (#17664528)
You can access the raw DOM node from a React component.

On component mount/unmount, you can apply a jQuery library to the DOM node and optionally clean it up.

It's the same way you can wrap a <canvas> node with a React component and otherwise do all your draws outside of React (like for a game). This way the node is still integrated into your React app but React does nothing more than create/remove it.

Re:Django 2.1 released by blackrock on Wednesday August 01, 2018 @11:46AM (#17663569)
Thanks for the input. Comments like these are insightful.

What do you think of Vue.js?

Re:Django 2.1 released by duiker101 on Wednesday August 01, 2018 @12:08PM (#17663807)
I have spent some time using Vue.js and Django as a backend and I have been pretty satisfied with the results! I will probably try React next just to make sure I am not missing anything. I tried using node as a backend but I couldn't find any framework on the level of Django so I went back to it. There are some pretty decent boilerplates already to setup a Django/Vue website if you look for them.
Re:Django 2.1 released by johnthedebs on Thursday August 02, 2018 @12:43AM (#17669272)
I've heard great things about Vue.js (mostly on HN) but I haven't tried it myself. I'm pretty invested in React (I use it at work and for personal projects), and I find it to be a pleasure to use so I'm not actively seeking out alternatives.

State management with React is another story; I've used Reflux and Redux a lot, and am experimenting with Mobx now.

Re:Django 2.1 released by kennydude on Wednesday August 01, 2018 @12:18PM (#17663927)
Vue is a pleasure to build stuff in. It just seems to work well, especially with nice things like two-way binding out of the box.
Re:Django 2.1 released by ergo14 on Wednesday August 01, 2018 @12:02PM (#17663748)
Vue looks nice, but nowdays I'd pick something like lit-element(lit-html) or stencil.
Re:Django 2.1 released by mrfusion on Wednesday August 01, 2018 @12:18PM (#17663918)
I’m curious what makes react your top pick?
Re:Django 2.1 released by johnthedebs on Thursday August 02, 2018 @12:41AM (#17669269)
Compared with Backbone, I was able to compose and re-compose component structures much more easily. Compared to Angular (which I admittedly don't really know) the API learning curve felt very short and I was able to wrap my head around it very quickly and be productive without constantly looking things up.
Re:Django 2.1 released by anchpop on Wednesday August 01, 2018 @11:35AM (#17663458)
Django fan here, if you're trying to use Django with react you may be interested in this: https://github.com/anchpop/cookiecutter-django

I wrote it for my own convenience but others may find it useful.

Re:Django 2.1 released by Franciscouzo on Wednesday August 01, 2018 @11:53AM (#17663649)
Not OP either, but I've been using Django REST framework with React.js, and I'm really enjoying it.
Re:Django 2.1 released by knicholes on Wednesday August 01, 2018 @12:05PM (#17663788)
Any tips for how to use JWT authentication and get around CSRF tokens being in forms when combining DRF with a JS SPA UI?
Re:Django 2.1 released by theptip on Wednesday August 01, 2018 @12:28PM (#17664029)
If you want JWT, you can use https://github.com/GetBlimp/django-rest-framework-jwt -- that provides another authentication class, and you can then auth with `Accept: Bearer <jwt>`.

If you don't need JWT (I'd probably leave it out next time round) then Django Rest Framework comes with a simpler bearer token auth class (among others): http://www.django-rest-framework.org/api-guide/authenticatio....

edit to add - if you're asking specifically about sharing sessions between the JS app and the Django server-side form, I believe this is what you're looking for:http://www.django-rest-framework.org/api-guide/authenticatio..., i.e. you'll still need to pass the csrf token into the JS app.

Re:Django 2.1 released by kennydude on Wednesday August 01, 2018 @12:15PM (#17663887)
The way I've always done it is to not log the user in to a Django session. That way the SPA is the thing which holds the authentication, be it JWT or any other kind of token.

If any other site tries to POST to the API on behalf of the current user they'll get a "Authentication credentials required" message.

Re:Django 2.1 released by ransom1538 on Wednesday August 01, 2018 @12:19PM (#17663929)
Yes! It is just like Rails. Almost as good! Is it Python 2 or Python 3?

https://wiki.python.org/moin/Python2orPython3