I'd recommend a section on 'Function Based Views' in there as well. I've personally found the CBV-based approach is sometimes good but in most cases I still prefer the FBV approach. You see it often enough that I think it is worth going over in detail.
Is there any reason to still use them though? You could always just define a `get`, `post`, (etc etc) method and have pretty much the same effect of a functional view but with the added niceness of what CBV's provide (mainly inheriting some other view with a lot of boiler plate)
…future expansion that I will probably never use. And I disagree that it's just as simple. I think that CBV's encourage me (and my team, because I'm not working in a vacuum) to think about the problem all wrong. You may like thinking of the problem that way but for me it's like trying to think of a song while another song is playing. I usually think of Django views as a function, not a method on a class.
Django's FBV's are far from perfect and I think they really could benefit from some small changes to the way things are done, but I agree with the above links that CBV's were a step in the wrong direction.
I recently ran into issues which I could only explain as CBV not being thread safe. self.request.user would not remain consistent when a view needed to save multiple models. I haven't had time to fully debug, I only know that frantically patching to not rely on properties, rather arguments, fixed it. We're also running gunicorn on Heroku, not sure yet if that's related. Either way, something to consider.
This is wonderful! I feel like the django documentation, combined with 10,000 stack overflow questions is the wrong way to get started, and yet, that's how it was for me. I will use this all the time for tips and pointers. Thanks!!
I don't know if this is the absolute best way but Two Scoops of Django recommends having a tests folder in each app. So tests for example_app/views.py are placed in example_app/tests/views.py.
yes, you put it in the tests.py file in your app directory. That way you can just run "python manage.py test myapp" and every test in myapp/tests.py will be executed.
This is awesome. I haven't touched Django even though I develop in Python on a daily basis... been meaning to but hadn't found a reason to. I've bookmarked this for when I finally get the itch.
Btw, there are some weird formatting issues in the tutorial (underscores after links?).
Writing the server side of an AJAXy search was pretty straightforward. In your view function, Instead of rendering a template, you call json.dumps() (or the equivalent in XML), and set the content type of the HTTP response (i think "application/json"). Django won't generate your client side JavaScript for you (nor should it IMO), so use jQuery or whatever you want.
good point! django doesnt have any built in http resposnes or decorators for returning json (as far as i know anyways). I would recommend looking at these two options:
Many web apps/services now use at least a little AJAX. Certain things in a framework can make it easier. Some discussion of how AJAX techniques, up through 'single-page apps', can use a DJango back-end would be nice. (Maybe not absolutely necessary... but nice.)
Then, a bit of docs about the JSON apis to use, and caveats/gotchas in using them with Django Models would be helpful. The popular Django extension TastyPie could be discussed, as well as URL schemes compatible with common client-side libraries.
Similarly, ways to mimic single-page-app URLs from the server side, for first-load speed or SEO benefits, could be discussed.
What is a JSON api? Anyway, your entire wish list is out of the scope of the document. If you want to know how to build a hypermedia API (which I think is what you meant by json api) what does that have to do with "effective Django"? That would be "building effective hypermedia APIs using Django".
A JSON API is the methods & options that are available for (de)serializing your native Python or Django objects into useful JSON.
Perhaps there's a more narrow 'scope' defined for this project, but simply from the title, it seems an 'effective' Django developer would appreciate guidance for the best ways to do AJAXy things (including, especially, RESTy web services for backing AJAXy front-ends).
AJAX is nothing more than sending and receiving data from the server to the client. That's what views do, and they are documented.
There is also an is_ajax() test in Django (not that useful) and various apps that provide REST interfaces that you'd probably want to use for bigger AJAX-y apps.
This frustrates me. Three hours of time to watch a video, if you charge $50/hr means you spend $150 opportunity cost of time on the free version. Assuming the time to consume both is equal, it gives an equivalent cost of $150 vs $164, or put another way, the difference in cost is a rounding error.
It seems to me the only durable advantage to the free version is that if it isn't working out you can abandon it after 15 minutes at a fraction of the cost. If there were a credible way to sell knowledge products "satisfaction guaranteed" I'd think that people would be a lot less sensitive to the difference between free and $14.
considering that I already know python, if I wanted to make a good looking personal gtd type webapp, am I better off learning django or should I rather learn node.js?
I worked with Nathan (guy behind Effective Django) at Eventbrite for a few years and highly recommend him as being a very informed python and django expert.