11. Setting up a project Photo credit: http://www.flickr.com/photos/thedailyenglishshow/6013713229/ Disclaimer! The following slides were not in my talk: I did a bit of a live demo instead. So these aren’t 100% complete, just a flavour of my talk.
12. It worked! So, I’m not going to cover installing Django… it’s really easy to get a local set-up, just follow the installation docs on the Django site. When you’ve done that you should end up with this, once you run the test server:
22. In Conclusion Photo credit: http://www.flickr.com/photos/wonderferret/306390009/
23.
Notas del editor
Hi. My name is Jen, you can find me on twitter as @jenofdoom . I work at Catalyst IT as a web developer. I'm here today to talk to you about the Django web framework at quite an introductory level, i.e. for n00bs.
There are two potential audiences for this talk: those of you who are familar with Python and have used other frameworks but don't have any experience with Django, and are looking to simply learn what extra Django might offer; and those of you who might have used other frameworks or content mangement systems but haven't used Python before. I'm going to try and cater for both of those groups in this talk (possibly focusing on slightly on the later), but of course the caveat of this is that I may not go into quite the same level of detail that I would be able to if I was targeting one group over the other, so if you have any questions please feel free to ask them at the end. I personally feel that if you are new to Python as a language, as long as you have some experience with a programming language of some description and you understand basic control flow stuctures, Django is an excellent gateway drug to serve as introduction to Python for the web, as it does a great job of handling a lot of the intial futzing around with configuration and allowing you to just get on with writing code that does stuff, quickly. There are plenty of great resources for picking up Python available online and I'd recommend just taking a basic language tutorial to make sure you've got the concepts down before starting with Django. I myself am a long way from being a Python expert of any description, but I do use it for my day job and I'm a big fan as it lets me Get Stuff Done.
So what, exactly, is a framework? I'm sure most of you know already, but here's a quick refresher: "A web application framework is a software framework that is designed to support the development of dynamic websites, web applications and web services. The framework aims to alleviate the overhead associated with common activities performed in Web development. For example, many frameworks provide libraries for database access, templating frameworks and session management, and they often promote code reuse." source: the ever ubiqutous wikipedia http://en.wikipedia.org/wiki/Web_framework Really though, putting this quote aside, I feel like this picture does a pretty good job of explaining what a framework is – it’s a basic structure that you can then build upon further.
Some of you may be more familiar with the concept of a Content Management System when you think about web applications, such as Drupal or Joomla etcetera. These CMS's have great advantages when it comes to getting up and running and solving common functionality needs quickly, but if you are doing something really bespoke they are definitely lacking, requiring a lot of wrangling to make them do what you want to do, and using up a lot of additional overhead for functionality you may not find of use. Conversly, a framework is a lot more bare bones. You are going to have to do a bunch more work to get up and running, but because you are putting in only the code that is relevant to your aims, you have a lot more flexibility and hopefully you will end up with a much leaner application.
Django originated at the Lawrence Journal-World newspaper in 2003. In the summer of 2005 it was released as an open source project. Yes, it is named after Django Reinhart, the guitarist. Django took a big step forwards in maturity with the release of version 1.0 back in 2008, and it's now up to version 1.3 with a major release roughly once a year.
Of course, Django is not the only web framework. Ruby on Rails is a big fish of course, and on the Python side of things we have not only Django but also a handful of other frameworks. Briefly, some of these are: Pyramid (Pylons) -> Pyramid is the result of a merger between repoze.bfg and Pylons, and it's a lightweight framework that offers very good performance plus a modular approach to choosing for example, if you want routes or url traversal, or if you want mako or chameleon templates. It's much more bare bones than Django and generally you will be writing some code to glue things together. Zope -> Zope has been around for quite a long time and has branched of into a bunch of different project such as BlueBream. Zope includes ZODB, an object database for Python, plus a bunch of standard libraries. Bottle -> Bottle is more of a micro-framework for very small webapps. There are a bunch of these, such as CherryPy, and typically they don't provide much beyond some basic url dispatching and an http server to build-your-own on top of. TurboGears - > I confess I don't know that much about TurboGears, but it takes a similar approach to Django in that it is a 'full stack' solution, except it's using open sourced components. It's now built on top of pyramid I believe.
So why would I pick Django over these other frameworks?
Biggest fish -> Perhaps this seems a bit self-evident, but one major advantage is that Django is pretty popular. More users means more people to ask for help if you get stuck. It also means there is a nice big community of folks writing tutorials and creating add-ons. Tightly Intergrated Components -> Django takes a very much all-in-one, batteries-included type of approach. The url dispatcher, object realational model, template system etcetra all come as part of the package, and they are all specific to Django. The great advantage this offers is that everything meshes together really well. Admin interface -> In terms of wow-factor when you are demoing Django, the built in admin interface is defnietly one of the nicest features. We're going to have a look in a minute at how easy it is to get this up and running. Documentation -> Django has really nice, pretty, well-written, logical documentation. I really can't praise it enough. It's both easy to understand for newcomers and offers plenty of depth for those needing technical information. Well thought our release process -> Django does a really good job of giving you plenty of advance notice about what features are going to be changed or deprcated two or three major releases away. The release notes offer solid advice about what you need to do to get your existing apps up to date. Authentication & security -> Finally, it's great to have all your user authentication and permissioning taken care of out of the box, as well as CRSF protection. As with a bunch of the features mentioned above, if you don't want to use it, it's realy easy to turn off and substitute something else. Of course, for some people and some situations, some of these upsides could be considered as downsides. There has been some criticism leveled at Django with regards to the amount of its functionality that was created from scratch as opposed to using already established open source componements. This could in theory take folks away from the established components, and generally reduces interoperability. There is essentially only a small core group of people that actually guide Django, and there is some feeling that if your thoughts don't match their intent you need to be be prepared for a little frustration that features you care about won't get folded in. Right now Django is Python 2.x only. It seems likely that eventually Django will support Python 3, but it could be a long time coming due to their release process' ongoing support of deprecated features through at least a couple of major version changes. Personally I don't feel like any of these concerns are significant enough to impact my use case, but your mileage may vary.
We're just going to pause for a second here before we dive into setting up a project. Hopefully most of you are already familiar with the MVC model, which most Python based frameworks use. Briefly, when we lay out an application in an Models-Views-Controllers way, we split up the application into layers, keeping presentation seperate from the program logic, and keeping that separate from the data model.
One gotcha to those of you coming from other MVC frameworks is that Django has a slightly different interpretation of what MVC means. Django's approach could more accurately be described as 'MTV' (nope, not the channel), which is: Models, Templates, Views. Basically, in Django's inteterpretation, the 'view' describes the data that gets presented to the user, i.e. it is a Python callback function for a particular URL. Then all the presentation gets seperated out into the templates, as I'll show you.
OK, I think that's enough bullet points for now, I think it's about time we got our hands dirty. So here's an incredibly brief look at getting a project up and running with Django. Ok, so let's pretend we're creating a simple website for a group of friends to be able to log in and vote on movies that they want to see when they next hang out, to save a bunch of arguements on the night.
Right, so getting Django set up locally for development is pretty straightforwards, you can follow the instructions on the Django site to get in installed so I'm not going to cover that. For similar reasons, I won't cover initial project setup as I want to just jump straight in to actaully making a site just to give you a taster of that.
I wanted to cover forms as wel,, but alas no time!
I love frameworks because they allow me to build a project hey way I want it to be built. I'm a big fan of Django in particular because it’s so quick to get up and running. My first introduction to Django was a 15 minute youtube video which showed someone putting together a simple wiki system. This talk is my attempt to pay forward some of the excitement I felt watching that initial demo. I hope that your have found it useful.