Django 1.9 alpha 1 released
djangoproject.com
djangoproject.com
Young dev: "So, what's your backend?"
Me: "Django"
Young dev: "What?"
Me: "Django, a Python framework."
Young dev: "Oh, right, that old framework. It must suck to support a legacy app that's written in something so outdated."
Me: "Well, we kinda use Django for everything."
Young dev: "Wow, doesn't everyone just use JS these days?"
Btw, I'm 36.
The reason I reach for Node on a project is to handle my websockets. I use Django REST Framework + Ember as my main tools (super fast to build with) but, based on my testing, Python can't hold a candle to Node when working with thousands of websockets. It works great for what it was designed for.
I'm building a side project right now and I'm using Django running inside Tornado (it's pretty simple to setup, really) so I can both have my cake and eat it (easy APIs, and a layer I can use to maintain websockets.) I wonder if the performance would be comparable to Node?
Although Ember really feels like idiomatic Javascript to me and they try hard to adhere to new web standards (e.g. web components, ES6 modules) it is also very opinionated about what should go where and how.
This may not be the venue for me to surface this, but I've been trying to wrap my head around the MEAN stack for about a month now, and it doesn't really even register to me as the same language. I'm using Angular on the front end and ExpressJS plus Mongoose (MongoDB) on the back end, so yeah, it's all technically Javascript, but the real learning curve was in working out how to get these big frameworks to do what I wanted. I sincerely believe that if I was using an Angular frontend to call a Django REST service, I'd have had the exact same amount of trouble grokking what was going on (async calls being the obvious exception).
Am I thinking about this the wrong way?
You only spend some time grokking the basic syntax of the language.
Most of the time is spent getting the frameworks working and talking to one another. The frameworks having the same underlying language does not gives you much advantage.
- Joel Spolsky in Things You Should Never Do, Part I [1], saying source code doesn't rust.
- Old Code Rusts [2], arguing that source code doesn't change by itself in the way that a car can rust "by itself", but the environment in which the code is used is always changing
So maybe Django is already old fart technology? Well if it is, then it's a pretty powerful, solid, productive, reliable piece of old fart technology standing upon other pieces of old fart technology that, despite environmental changes (as defined in [2]), remain powerful, solid, productive, reliable tech powering many websites. I'd just cheer with young_dev to party on, Wayne, and go with whatever floats his/her boat.
[1] http://www.joelonsoftware.com/articles/fog0000000069.html
Bad news: I'm obviously kidding here, but it's based on a true story.
What are the preferred solutions for:
* an RDBMS ORM?
* forms?
* templates?
* authentication?
* permissions?
* file storages?
* sessions?
* REST?
* internationalization and localization?
* caching?
* logging?
* mail?
* sitemaps?
* RSS/ATOM feeds?
and security: * XSS?
* CSRF?
* clickjacking?
* SQL injection?
* ensure secure connections and cookies?
I mostly use Django because I want to get stuff done, and with Node (as of a few years ago) it seems you have to rewrite the world.All in all, I've always been a Django advocate. I know people hate the "batteries included" approach, but it guarantees that all parts work together well, and you'd be surprised how much of it is easily replaceable/removable. I've even used Django as a bare-bones router/request handler framework with great results.
Unless you need to extend or modify the behavior in an unsupported manner.
Django got much better since early 1.x versions, and gets better with every release, but I still find myself monkey-patching its internals (or copy-pasting classes with some minor changes) once in a few months.
I should go back to Django again, I started out with 0.90 when I first learned about MVC with Python.
From there, Node isn't that big -- it's a few libraries for interacting with the system. The assorted framework stacks and whatever haven't really sorted themselves out yet.
From a technical standpoint, what Node does well is that it's basically async-IO-by-default, which is very nice for real world performance, whereas in most-every other environment I've worked with async-IO feels like an unwieldy addon where example code is hard to come by.
Also, 3 to 5 years from now is where I'm aiming at (JS will be "stable but still cool").
I think Node today can solve these 4 problems well enough.
Both projects had (probably still have) a culture where if someone needed something, they'd first google for an npm, pick something, and just npm install that. Bleeding edge was viewed as a good thing. Kind of reminds me of the times when a new jQuery plugin was added for every little thing.
Soon, both projects will be using a large number of abandoned or obsolete npm packages which have been superseded by even more bleeding edge stuff.
Some day the dust will settle and preferred solutions will emerge for most things. But right now, man, it's a wild west.
Maybe Im being ignorant, but I don't remember even Rails being this crazy in its early heyday :)
I'm going to get a lot of hell for this since this is startup-land-latest-and-greatest-just-graduated-from-Stanford territory, but WebSphere and J2EE really got everything down for a god damn reliable infrastructure, REST or WSDL compatible, authentication/authorization via any provider you want ranging from Novell Netware to LDAP or AD, caching can be thrown in _every level_, if an appserver goes down, another node picks up the abandoned client sessions, you're getting high availability at just an absolutely remarkable level. Hate on maven (I've been down in the trenches with Scons and the GNU autotools set, you can get far worse) all you want but the ability to freeze and clone all of your dependencies into a local .m2 repository allows you to be 100% confident if an upgrade breaks functionality, regress & problem solved. I'm not even a J2EE advocate, more of a "please just work, I don't have the mental capacity to learn 60 packages + 15 workaround shims until all browsers are ES6 compatible.
I really like a lot of the options of node out there. Tons of packages are really useful and innovative (as opposed to Yet-another-templating-system). There are quite a few interactive projects that the v8 platform lends itself to, especially with socket.io, a lot more flexibility that didn't exist before. But between ReactJS, Flow, JSX (which confuses me even more when I context shift because I write C# with TypeScript), and 50 other packages out there, I'm completely lost.
From a managerial perspective, its going to be hell to maintain those projects 3 years down the line when all of your 22 year old engineers have moved onto their own startups/friends startups/across the country because their long-time-partner got into Harvard med/etc. You'll be left searching for someone with expertise in Jade, Express, Node, Mongoose, Nginx, Socket.io, JSX, [insert 10 other modules which will become critical to your architecture as time goes on]. It's great for the engineer who lands inherits that project on a 1099 capacity because they'll be able to bill whatever they want, but absolutely terrible in terms of long-term maintainability (and yes, I realize technical debt is often a "bond-offering" (heh) worth making in exchange for a faster MVP in some cases).
forms : I gave up on form builders few years back, write them by hand
templates : EJS(prefer personally), Jade
authentication : passport.js, just works
file storage : node's fs module for local file's, aws node's sdk for s3
sessions : express-session with redis client and all
REST : express.js (supported by IBM, of all companies, heh), and restify, built over express
internationalization and localization : No idea, haven't had to do this one yet
caching : depends on the use-case, for request-response level caching, check out express middleware for the same, use ioredis for other things
logging : metalogger
mail : I mostly use a mandrill client, but I bet you'd find a few really good mailing implementations. You have an industry grade mail-server (haraka) in node world, so finding a mailing lib shouldn't be hard
sitemaps : Again, haven't needed them yet
RSS/ATOM feeds : haven't needed them yet
XSS : tackled by EJS, Jade etc templating engines
CSRF : express-csrf middleware ftw
clickjacking : helmet
SQL injection : knex.js
Secure connection and cookies : express + express-cookies middleware.
Finding each of these libs is a matter of 10-15 min of research, looking at number of downloads, frequency of downloads, contributors etc. And they just fit together really well.
You mostly don't need all the features you listed in all of your projects. Using node's libraries, with some effort, you can build a framework tailor-made for your project.
Hope that helps.
[0] http://gilesbowkett.blogspot.com/2012/02/rails-went-off-rail...
We just got done migrating five complete websites to new hardware. In that process one had to be completely re-written from scratch and the other four had various levels of tweaking, adjusting and fixing.
The process was smooth as silk. No problems at all with deployment, live site testing, etc.
Oh, yes, these were all PHP sites.
I don't want to go into a Python vs. PHP discussion here. I'll simply say I am not a fan of PHP and by far prefer Python for most web (and other) work.
And still, I have to say, when it is time to deploy a Python site we have to go through a checklist to make sure every little gizmo that needs to be in place is in place. Well, now we have Ansible scripts, but that's besides the point. With PHP we just FTP from our local repository to the live server and it's up and running with almost no setup.
I also have to generalize and say that most of the Python/Django sites we've worked on are far, far more complex and involved than the typical PHP sites we see. This is where, to me at least, Python/Django shine.
Anyhow, maybe we are being lazy. Don't know. It'd be interesting to hear from others who might do a lot of Python/Django work.
Setting up some routes, the virtual environment, and env variables is a breeze. It's easy to test locally to see if it's breaking, and trivial to restart.
uWSGI is a pretty amazing piece of tech. A small binary which can do practically everything you need out a web server, really fast, and simple to configure.
I repeatedly use this for all my deployments and refer to my own notes during deployment.
My notes here: http://blog.busilogic.com/deploy-python-uwsgi-app-to-digital...
It's not as easy as deploying a PHP app, but overall the python/django stack with uwsgi feels right with enough options built in to suit your needs.
Technically you can do that with Python as well depending on your setup. Although you may need an extra step such as "touching" your wsgi.py file. If you aren't caching your templates[1] (which you should in production though), you can upload template files and see instant changes.
[1] https://docs.djangoproject.com/en/1.8/ref/templates/api/#dja...
Also, I find deploying with mod_wsgi or uwsgi not any more difficult or time consuming than getting PHP-FPM set up and running.
Yes, if you have a brochureware site with a few bits of database interactivity, you can just FTP a few files somewhere and have your PHP app up and running. The moment you start to introduce elements such as background queues, or more than a few developers on the team, you start to get into the realms of needing something more robust and doing config management.
Facebook uses PHP. I very much doubt their deployment process is to FTP a few files to the right place.
Setup the post_update git hook script to checkout to the webserver path and run django admin commands to collect static files and sync the database.
You can also setup a test environment to run your tests first, before updating production.
Coming from a .NET background, where everything is done through the point-and-click IDE, I find it couldn't be easier and pain-free than that.
The guy is just more uninformed about the web development landscape than you are. He's like the Java or Microsoft of 2000's, that only knew their own part of the development landscape. In other words, Blub to the bone.
Lets say you have a page for location based doctor search. When the search form in this page is submitted, wordpress makes API calls to django backend where real search happens and a list of doctors is returned to wordpress. Wordpress then genereates html and send it to the browser.
Similar process for dislaying a specific doctor details.
The CRUD and other application logic for doctor data is handled in Django. And with rest API you can then create a web based UI or a mobile application.
I haven't seen a good description of how to pull this off... but it would make a great eBook (I'd buy it!).
It seems like the Django RESTful API would be one solution... but it would result in a lot of extra REST requests (so blocking & latency) being generated during server-side rendering, so perhaps not the best solution.
Thoughts?
(I am aware of solutions like this, but it misses the server-side rendering aspect with contexts: http://stackoverflow.com/a/28646223 )
For client-side, everything works as normal: The React code starts with static values for state/props that are pre-populated (ie. the return value for getInitialState was already determined during server-side rendering). Upon app updates (eg. user interaction), the app will make asynchronous calls to the correct REST endpoints -- perhaps batched, as you mention. Client-side is the "easy" part of this one. :)
For server-side rendering you have a normal HTTPresponse-returning Django view (eg. for /). That view compiles/renders the React JSX "template" in NodeJS. Only for server-side, when you call renderToString to get the initial HTML, getInitialState is actually a series of REST requests (in javascript) which are batched, sent to django, and returned (map-style) to node as JSON for initial rendering.
Two questions:
(1) Does the REST request batching get sent to a different, special endpoint for batching? Or when you say "middleware", do you mean that any REST request is capable of being a batched request via the middleware?
(2) There seems to be some nuance in structuring getInitialState (or props) so that it makes the REST calls on the server-side, but not on the client-side. I'd be curious to see how you structured that.
PS -- You might shoot me an email (in profile) since this is somewhat OT to the thread? I'm super-appreciative of your insight!
The the server-side rendering description is a bit off. We have the Django REST framework server that never serves HTML except Django Admin. All pages go to the Node.js server which renders the HTML using React, and sends it through when the page is loaded. The same react code is also loaded onto the browser to update the HTML asynchronously later. We have two projects setup - one django project and one node project.
"Only for server-side, when you call renderToString to get the initial HTML, getInitialState is actually a series of REST requests (in javascript) which are batched, sent to django, and returned (map-style) to node as JSON for initial rendering."
Sounds mostly good, except we return the list of responses using the protocol I've linked to in the comment. (multipart response with boundaries, responses written one after the other in the same order as sent). This is taken care of by the middleware and is transparent to the rest of the node/react code. The data gets parsed as usual into JSON and used for initial rendering.
1. Yes. It's a special endpoint for batching. By "middleware" I meant client-side middleware. On django it's just a view we've written, that parses the request(s) and puts them through django's `WSGIHandler`, and extracts the responses and render them one by one into the same HttpResponse.
2. I've posted how we've done this in another comment. :)
I've hoped for years they'd use bootstrap, how does this compare?
https://docs.djangoproject.com/en/dev/_images/admin02.png
https://docs.djangoproject.com/en/dev/_images/admin05t.png
And here are the same screenshots from the 1.8 version of the tutorial:
https://docs.djangoproject.com/en/dev/_images/admin02.png
https://docs.djangoproject.com/en/dev/_images/admin05t.png
And here are the same screenshots from the 1.8 version of the tutorial:
However the fact remains, as I assessed about two years ago, that the momentum behind the Django ecosystem is as stagnant as ever. Many third-party libraries are deprecated or ill-maintained. This is as much symptomatic of Python as a whole as Django, but regardless it exasperates the slow release cycles when compared to other languages and frameworks.
My money is still on JS/Clojure/Erlang/Go/etc. to carry us into the future of web development. No doubt Django will fight to the bitter end with its strong enterprise support and mature codebase. I'm ok with that, it's just not for me anymore.
Django Rest Framework appeared on Thoughworks radar under Trial this May (https://www.thoughtworks.com/radar/languages-and-frameworks), momentum is anything but stagnant.
There's literally nothing you can do on the newest, flashiest (read: unstable, poorly documented, non-battle-tested) frameworks that you can't do using a combination of Django and Tornado/Twisted in half the LOCs and using mature libraries. The same could be said about Ruby on Rails, or even something like Spring Boot for Java or Spray/Scala.
I don't mean to deflate innovation, but innovation for innovation's sake is rarely useful.
Take a look around and the equivalent libraries of the languages you mentioned. Honestly, the quality of similar libraries for the functionality that you need is lower, and the featureset smaller.
Javascript suffers from all the problems of a "teenage" tech: immaturity, lack of established libs, poor documentation, and some astoundingly bad coding practices out in the wild.
Clojure's ecosystem is very small, and has the same issues with code stability and lack of decent mainstream library alternatives.
Erlang, though a great language, has some issues with its unfriendly ecosystem and a general lack of libraries for many common tasks.
Go, while gaining serious momentum, still seems to suffer from a substantial lack of features to compete in the same rapid development niche that Python, Ruby and JS attempt to point to, although it was never meant for that role anyway.
Notice how the people above talking about WebSockets aren't being downvoted because it's both real and specific enough to have an actual technical discussion?