Diving into Django
videos

Diving into Django

It’s always nice to branch out from our usual topics. For today’s screencast entry, Jeff Hui will show us how to build a basic ticket management system, similar to Lighthouse. Though the project won’t be nearly as advanced as Lighthouse – for obvious reasons – it should make for a nice starter for newcomers to the Django framework.

Read On…

If you’re intrigued and would like to learn more, be sure to read our recent “Intro to Django” tut.

  • Subscribe to the NETTUTS RSS Feed for more daily web development tuts and articles.


Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • Jeremy

    Nice to see some django love on nettuts! Nice introduction!

    I’d also point out for people looking to see more introductory screencasts on django, the “Django from the Ground Up” series on ShowMeDo is also excellent, though gets a lot more in-depth working with models than one would expect for an introduction.

  • http://www.zettersten.com Erik

    That was a complete introduction to Django for me. Well done Jeff, not too many “umms” (=

    I love Django’s user-friendly syntax.

    Cool…

  • Hassan

    Could you please have a mirror for screencasts? in youtube or something…?
    Thanks.

  • http://www.affiliateslive.com/ Andrew

    Good stuff always looking for some more great stuff on Django. Maybe in the future you guys could cover CakePHP.

  • ger

    Great screencast!!
    I want more stuff about django :)

  • http://www.zaba.si Oto Brglez

    Awsome tutorial Jeff! Great job!

    Can u please please create srcreencast for django about user profiles, login ,logout, registration. Srcreencast about user system perhaps.
    That would be really nice.

    Thanks again for this knowledge!

  • mohammed

    thank you very much

  • http://jeffhui.net/ Jeff Hui

    Thanks!

    I intend to make a series if Jeffrey Way doesn’t mind ;)
    Although I’ve gotta get exams out of the way first. Also if you’d like to see a demo (although it isn’t really interesting) see http://demo.jeffhui.net/simpletickets-1/
    Sometimes it takes a bit to load since it needs to spawn a processes to load the page if it’s been inactive.

    P.S. Jeffrey Way, those links in my profile doesn’t work.

    P.S.S. How do you get gravatars to work?

  • http://jeffhui.net/ Jeff Hui

    Ah, nevermind about the gravatar thing…

  • http://www.image2markup.com berofx

    Great stuff, please make some more :-)

    A quick question: I see you’re using GVIM as the editor, but what is the name of the utility you use to browse/open files? (the one that appears in the top left corner)

  • http://www.jashsayani.com Jash Sayani

    Wow!! Time to make my own Collabtive !

  • http://hostdkr.com Devin Rajaram

    how do you make what button you click on show up when doing the screencast just like mac?

  • http://selectwebdev.com Stephen Coley

    Which text editor are you using? I’m on a Mac, so I doubt that it will better, but I’m just curious. Nice screencast by the way.

  • http://jkb.name/ Jonas

    More Django stuff like this, please!

  • http://synarchydesign.com Kevin Martin

    Whats that program that youre using to switch around to Chrome and more around 3 minutes in where you are typing and its giving you suggestions?

  • http://michaelnichols.info John Nichols

    We need more Django tuts! Great Video!

  • http://yoosuf.awardspace.com/ M.A.Yoosuf

    @Stephen Coley: its VIM editor i guess, try for http://www.vim.org/download.php#pc

  • http://yoosuf.awardspace.com/ M.A.Yoosuf

    @Jeff Hui i have no comments, because i have no interests in PHYTHON cum i have no idea, but hura, you have done a good video, all the best. i got to know some configuration stuff in Phython, hope i will be able to give support any one because of this video

    Thank you
    Yoosuf

  • http://gbgravity.com Alex

    Good tutorial Jeff. I’m glad to see more Django stuff on Nettuts. Python is a great language and Django is a great framework. It really helps cut down dev time on applications.

  • http://derekorgan.com Derek Organ

    For those wondering what he is using to open different items, its called Enzo

    http://humanized.com/enso/

    pretty neat but really he could do all of that by just pressing the windows key in vista .. the search bar there does almost the exact same thing which most people don’t use supprisingly.

    Nice screencast, its a quick intro but love the way the admin interface can be done so quick.

  • http://blog.brenelz.com Brenelz

    I big problem I have with Django is all the command line stuff – and it doesn’t seem like a lot of hosts that support it

  • 47bytes

    @Brenelz just rent a v-server. It’ll cost you about 5€ a month and you’ll be able to install python and django and a database of your choice.
    So no problem there.

    PLUS you can host your django-app on google-app-engine because the google-app-engine supports python… check out http://code.google.com/p/google-app-engine-django/ to learn how to host your django-app on the google-app-engine ;)

  • Matt

    I would really not advise putting the admin meta information in your models. This should really be separated out into an admin.py file . Just my 2cents.

  • Matt

    Adding to my above comment, this also allows you to run your app without the need of django.contrib.admin.

  • http://jeffhui.net/ Jeff Hui

    Thanks for the comments! :)

    @berofx and @Kevin Martin I’m using enso as my program launcher ( http://www.humanized.com/ )
    @Devin Rajaram Not sure what you’re talking about exactly. Could you be a bit more precise?
    @Stephen Coley As berofx stated, I’m using GVIM (Graphical VI Improved). VI one of those old-school text editors for unix based systems. Then VIM came out which added some major features while GVIM just makes it function as a traditional window (instead of having to run things in the console).
    @M.A.Yoosuf Just curious, is there any particular reason for not being interested in python? I have quite a few friends that just don’t like the spacing requirement in python which i thought was unusual
    @brenelz Yeah, it’s pretty difficult to find a host that supports python and fastcgi/mod_python without renting your own vps. You could use the Google App Engine to host a django project; I’m using asmallorange which supports django with a bit of setup. However since it isn’t as mainstream as php or even rails, it’s a lot harder to host a django project. I’ll agree with you that there are a lot of command line stuff. I really wished there was a IDE that supported the commands via a graphical interface like eclipse’s rails support. Being spoiled by django’s syncdb command line feature, I don’t have to deal with SQL directly which is pretty handy in my opinion and not the best to implement syncdb as a gui app from a developer’s standpoint.
    @46bytes You beat me to the punch as I was busy replying to everyone else :) Thanks.
    @Matt Yeah, I really shouldof put it into admin.py, but I figured it would be easier to just keep it in one file since models.py wasn’t that big. In future tutorials, I may have to move it around though.

    For those that are looking into (G)VIM, I’ll have to put a word of warning, it’s learning curve is *extremely* high. It’s not a trivial to learn editor. I personally recommend you to stick to your current editor because of it.

  • http://www.freshclickmedia.com Shane

    Hi Jeff – thanks for making the screencast – I’ve never done one, but I imagine that a lot of work goes into it.

    It’s interesting to see Django in action, but there’s nothing there that made me think ‘wow!’ – nothing that’s going make me want to learn more. Python seems like a good language, and the likes of Google are one company that uses it, but it just doesn’t really do it for me.

    The matter of hosting support certainly is an issue – I know there are ways of hosting a Django app, but at the moment, it’s a hurdle that just doesn’t exist with something like PHP or even ASP.NET (dare I mention something from Microsoft on Open Source NETTUTS.com?).

    The command line is a proven way of getting things done of course, but wouldn’t it be nice if the grunt work was handled inside an IDE? Is there a nice Django-supported IDE or plugin?

  • Jeremy

    Another great hosting solution for django is Mediatemple. They offer grid-service that you can add “containers” for different types of frameworks to (django or rails for example).

  • Jeremy

    @shane – Speaking for myself, I do think the lack of hosting options is probably the biggest set back for django currently… BUT, the people who do use django use it for a reason… Many are python enthusiasts–which seems to be a favorite amongst most developers I know who have been exposed to it. I work in .NET at work, and its a pretty clunky framework in my opinion, and though PHP may have some of the most options as far as frameworks go.. and may be one of the easiest solutions as far as deployment goes (and I use that somewhat loosely as its becoming less and less the case), its becoming *dated.*

    Django is called “the web framework for perfectionists with deadlines.” I think that really has a lot to say about the sort of people that it attracts, though it has a very powerful template system for the less development inclined.

  • http://zachlebar.com Zach LeBar

    I was psyched when I saw this show up in my NETTUTS podcasts area. AWESOME job! Being a student myself I understand priorities, but I totally want more. Maybe a more indepth application(blog, portfolio site, etc.), with a look at the planing behind it before jumping into the coding. Just some humble suggestions. Keep the good stuff coming!

  • http://www.pixmatstudios.com demogar

    This is the best screencast of the 3.
    Really great screencast, I enjoyed it really much and I liked two things also:
    - GVim: I don’t use Vim (I use e-texteditor instead) but I really like to watch people using Vim and how they improve their productivity.
    - Enso: I didn’t know about this application but believe me: I’m downloading it at this moment after your screencast.
    I use CodeIgniter (PHP) and Django sometimes, but it’s really awsome to have tutorials like this one to improve knowledge.

    Thank you very much and congratz

  • 47bytes

    Some people mentioned that they don’t like Python or that Python didn’t ‘wow’ them.
    So this post is to those people or to those, who need a reason why they should learn Python.

    I learned Python last summer.
    My first programming language was PHP.
    At that time I really was into programming web-apps but then I kinda lost interest in websites because I don’t program for a living yet and I just couldn’t think of a website that I want to program .
    So I started learning JAVA.
    JAVA is fun and all but some things in JAVA are ( in my opinion ) pretty annoying but that’s another story.

    So I programmed in PHP, JAVA , and C before I started learning Python.
    I started learning Python because of Django and because I wanted to get back into building web-apps.
    And Python blew my mind.
    Especially if you already know a programming-language I think you’ll really admire Python because thinks are so much simpler than they are in JAVA or C.

    e.g.
    foo = [1, 3, 5, 9, 10, 15, 21] # this is a list… basically an array

    if the number 3 is in that list you want to say ‘yes’

    if 3 in foo:
    print ‘yes’
    else:
    print ‘no’

    >>> yes

    note that if you write:

    if ’3′ in foo:
    print ‘yes’
    else:
    print ‘no’

    >>> no

    This is because although Python is loosely typed it knows the different between the int 3 and the string ’3′.

    You want to print the whole list but after each number should be a ‘\n’ ?

    for x in foo:
    print x,’\n’

    >>> 1
    >>>
    >>> 3
    >>>
    >>> 5
    ….

    If you want to do something with I/O in JAVA you have to mess with InputStreamReaders and all that stuff.

    Python:
    username = raw_input(‘Please enter your username: ‘)
    >>> Please enter your username: 47bytes
    print username
    >>> 47bytes

    Lets say you want to go print the value of all the ” elements from the nettuts rss feed.

    import urllib2
    import xml.dom.minidom
    urlhandler = urllib2.urlopen(‘http://feedproxy.google.com/nettuts’)
    parse = xml.dom.minidom.parse(urlhandler)
    elements = parse.getElementsByTagName(‘title’)
    for e in elements:
    print e.childNodes

    >>> []
    >>> []
    >>> []
    >>> []
    >>> []

    And that is just normal stuff I haven’t even talked about some of the ‘magic’.

    Finally I want to share a common feeling that you’ll get if you program in Python and you already know another ‘big’ language.
    It’ll go like this ( and I have experienced that feeling a hundred times ):

    ‘Hm… so I have to do X… well okey…oh know I have to mess around with sockets and all that crap…. shoot….oh what?… python already has a function that does exactly what I want? AWESOME’

    So instead of 10 lines code you’ll end up writing just 1 ;) :).

  • 47bytes

    In the xml example it should say:

    >>> [\]
    >>> [\]
    >>> [\]
    >>> [\]
    >>> [\]

    I guess there is a escaping error in wordpress

  • 47bytes

    Sorry for the 3 posts in a row but wordpress hates me.
    So again:

    In the xml example it should say:

    >>> DOM Text node “An Intensi…”
    >>> DOM Text node “Diving int…”
    >>> DOM Text node “Exactly Ho…”
    >>> DOM Text node “Working wi…”
    >>> DOM Text node “Screencast…”

  • http://jeffhui.net/ Jeff Hui

    @Shane I understand my tutorial isn’t convincing to learn python. It’s not suppose to. Someone would have to be a madman to make me a sales rep, since I’ll critique it to death before blindly advertise for a product I don’t truly believe in. However even if you don’t plan on using Django, learning other programming language is *good* as a programmer. Or else you fall under the “Blub Paradox” (see “The Blub Paradox” in Paul Graham’s famous article: Beating the averages http://www.paulgraham.com/avg.html ). Regardless if you even utilize the language in the end, it’s enlightening to see how other languages function and their working style. Although paul talks about lisp, it’s perfectly applicable to every language. Being real about it though, you probably want to spend your time learning languages that are generally more popular. Languages aren’t popular for purely arbitrary reasons ;)

    @demogar I was planning to use something other than GVIM for the screencast since it’s rather perplexing to users unfamiliar with it. However due to a broken right arrow, I stuck to screencasting in GVIM since not pressing right arrow on most other text-editing applications is a major draw back ;) I also considered CodeIgniter, but I didn’t really want to play “catch-up” on CI or PHP before starting.

    @47bytes Great brief overview of python! A lot better than I could do.

    I was intending on expanding this specific project to talk about various other techniques/features of django. Although I may have to consider a more in depth explanation of views (since this screencast basically evaded it) for the next one before going into more exciting features like built-in comments system, building your own backend (without django.contrib.admin), and ContentTypes.

    ContentTypes allow a powerful separation between models. This is how django’s commenting system works. You can simply “attach” comments to any other model and it just works. Pretty niffty in my opinion ;)

  • Ethan

    This is a great overview of Django! It was a bit rushed for my taste, but I was able to learn a lot from it!

    Quick question: Will you be able to run Python scripts on a webserver that does not run Python (but does run PHP and MySQL)?

    This is the only problem I have. I would use Python on live websites, but I can’t. I dunno.

    Thanks!

  • http://jeffhui.net/ Jeff Hui

    @Ethan I definitely agree, it’s feels a lot more rushed than I’d like. But I wanted a much better tutorial than a simple “Hello world” type example.

    Unfortunately, Python is required to run Django, so no, you can’t run python scripts that doesn’t have python installed. Although most default *nix distributions have it, but your host may only allow it via cgi scripts and CGI isn’t most notable for it’s speed (hence, there’s FastCGI).

    The cheapest webhost that can use django afaik is asmallorange which has a hosting plan starting at $25/year (although django isn’t “officially” supported).

  • http://alexwind.com Alex Wind

    I’m a Rails guy myself, I’ve tried Django, twice, and I could never get into it. I think I might do a Rails screencast soon :) Any app suggestions?

  • http://jkb.name/ Jonas

    For those of you looking for cheap Django hosting: Try http://webfaction.com/.

    HostGator is another option (they just installed FastCGI on all their servers), but setting up Django is harder at HostGator than at WebFaction.

  • http://chrisodonnell.name/ Christopher Francis O’Donnell

    I second WebFaction! Great service, which is what matters most, is very evident when you deal with them.

    Great tutorial Jeff! Cool to see how Django has gone from being a weird “they-don’t-use-the-MVC-acronym-and-RoR-does-so-I-don’t-know-want-to-use-it” framework to being nearly a mainstream system.

  • Dan

    Can these tutes be put on youtube so they can be watch on the iphone?

  • nanda

    The video is not getting played

  • http://jeffhui.net/ Jeff Hui

    @Derek Organ Thanks! :) Looks like you got that enso comment before me (probably awaited moderation? since I don’t recall reading your comment before). One of my primary reasons for using enso is that you can easily create custom launch commands and I find myself using “open with” more frequently than I’m conscious of. Both are lacking with vista’s startmenu launcher. It’s a fine replacement for something like launchy though.

    @Alex Wind You could try making a rails app for perhaps sharing file uploads or interfacing with another web API. Alternatively (plucking from one of my older ideas), you could try creating a chatting application (like campfire), which would be interesting, since I never actually learned about rails’ prototype integration (I always hand-wrote my javascript; Even in rails).

  • http://www.mykoala.com Andres F

    Nice job Jeff! I’m more enthusiastic about developing with Django thanks to you. I continue to learn a great deal from all of the authors and all of the fine folks on this forum.
    Thanks

  • Pingback: Inspiring Links for 2009-02-12 | This Inspires Me

  • http://www.pixmatstudios.com demogar

    I wanted to know something: is it neccessary to learn Python if I plan on learning Django right?
    I’m not the best Python/Django programmer so I want to start with it, what are your advices to start with Python and Django? Do you have a book advice?
    Thank you in advance!

  • http://jeffhui.net/ Jeff Hui

    demogar, it’s probably recommended to learn python before tinkering in django (just to understand python’s syntax). Although if you’re familiar with another programming language, you can breeze through most of python’s official tutorial: http://docs.python.org/tutorial/index.html within a few days of leisure reading.

    I’m not the kind that acquires book, but you could try getting something like “Python: in a nutshell”. Although I’m only recommending that book simply on the basis on that’s what google does ;)

    After understanding python (and perhaps make a few simple scripts), you can go ahead with django. You can check out django’s official tutorial via their documentation.

    As for books, I don’t quite recommend on getting any, since most cover the older 0.96 django version, which before the “magic removal” 1.0. I presume some of the information in those that are still applicable though. There’s http://www.djangobook.com/ if you want to read a book online for free. The second edition is a work-in-progress (which will cover django 1.0).

  • dom

    Hi!
    I was wondering what theme you use with vim.. it’s really awsome.. do you have also some additionnal rules (like it uses space when you tab, or anything else..?)
    I’m a linux guy trying vista.. would be nice if you could reveal some of your secrets ^.^

  • http://blog.webunusual.com Amr

    Keep the good work coming

  • http://lazypython.blogspot.com/ Alex

    Hey Jeff, good to see some RPI people using Django, I’m also a student here, do you think there would be any interest in a Python/Django meetup on campus?

  • http://www.josesandoval.com/ Jose Sanodval

    Jeff, great intro.