A complete blog engine using django in 60 minutes

I was inspired by this blog post to create this tutorial. It teaches us how to build a website with rails in 60 minutes. The tutorial is great and gave me a quick introduction to rails, which I plan to study in depth one day. Apart from that, I know nothing about rails, but I know enough about django to make the same and who knows, take it a bit further.

The goal is to build a full featured blog application using the django framework. By the end of this tutorial, you should be enlightened by many with the key features of django. Python background is not required, but it can be helpful in some specific parts of this tutorial. The final application should be capable of:

  • the usual CRUD (Create Read Update Delete) operations ;
  • display paginated lists of blog posts by categories, monthly archive and based on user search;
  • allow comments on posts
  • provide an rss feed
  • have some static pages, like an about page
  • use pretty urls

This is an ambitious goal, and you’re probably getting suspicious, wondering if all of this will be possible without third party modules or applications. Well, you can take my word, everything here is core python and django, and the entire application should take no more than a dozen files with an average 20 or 30 lines of code.

About the 60 minutes deadline, well, let me be honest, if you really want to understand what’s going on and are planning on follow the tutorial step by step it may take a little longer, otherwise, if all you want is to get a an overview of django capabilities, it can take even less time (depending on your reading speed ;-) ).

Have fun…

Table of contents

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay
  • DZone

Pages: 1 2 3 4 5 6 7 8 9 10

79 Comments

  1. SMiGL says:

    Nice post. Thanks

  2. seifsallam says:

    Greate

  3. [...] This post was mentioned on Twitter by Andrés Nieto, Jordi Cabot, Richard Laksana, Paulo Suzart, Matias Carranza and others. Matias Carranza said: RT @aNieto2k: http://bit.ly/5sgOm4 <– Crea un blog engine usando #django en 60 minutos. [...]

  4. Social comments and analytics for this post…

    This post was mentioned on Twitter by rlaksana: A complete blog engine using django in 60 minutes – http://su.pr/1PhNlx...

  5. HRCerqueira says:

    Thanks for the positive feedback

  6. Fernando says:

    Nice tutorial, well, on the page 7 , in the fist code box, the url pattern, i cant see the code with my brooser i see:

    “url(r’^post/(?P ”

    can someone helpe me with the right pattern?

    im using iceweasel and epiphany was broser.

  7. HRCerqueira says:

    Hi Fernando

    On top of my head i think is this:
    url(r’^post/(?P\d+)/$’, list_detail.object_detail, {‘queryset’: Post.objects.all(), ‘template_object_name’: ‘post’,}, name=”single_post”)

    Don’t know why (I think is the wysiwyg messed up the code) that code box was partially replaced by a flash object. Anyway I think is fixed now, I just reposted the code here just to be safe. Hope it helps.

    Cheers

  8. Luke says:

    Great tutorial! I have been using django for a while, but never really dived into the generic views and feed framework. I learned quite a bit from going through the entire tutorial. I also created a git repo of the entire tutorial on github while going through it step-by-step. The repo is at http://github.com/durden/django_blog. Let me know what you think!

  9. tamara says:

    life insurance no physical >:P low income health insurance 994945 cheap california auto insurance %-)) homeowners insurance in florida umbody

  10. Alexander says:

    error at / unknown specifier: ?P.
    I get this error when add the line on page 2 to url.py.
    What am I doing wrong?

  11. satlist says:

    >:PPP florida auto insurance =) auto insurance >:DDD auto insurance quotes 992

  12. reiven says:

    hi! great tutorial, i’ve found a couple of typos in the explanation but it works fine.
    i just want to know if you can recommend any “tag cloud” system for django. thanks

  13. Jorge says:

    Hi!

    Great tutorial, i’ve only got a question about the beginnings of page 7. When editing post_detail.html and adding {% url single_post slug=post.slug %} it shows:

    TemplateSyntaxError at /

    Caught an exception while rendering: Reverse for ’single_post’ with arguments ‘()’ and keyword arguments ‘{’slug’: u’las-cosas-van-bien’}’ not found.

    My urls.py is exactly as it has to be at that part of the tutorial:

    from django.conf.urls.defaults import *
    from django.views.generic import list_detail
    from mysite.blog.models import Post

    urlpatterns = patterns(”,
    url(r’^$’, list_detail.object_list, {‘queryset’: Post.objects.all(), ‘template_object_name’: ‘post’,}, name=”blog_home”),
    url(r’^post/(?P\d+)/$’, list_detail.object_detail, {‘queryset’: Post.objects.all(), ‘template_object_name’: ‘post’,}, name=”single_post”),
    )

    Hope you can help.

    • Jorge says:

      I’ve got it

      Two things to fix:

      1.- Firts, my fault, the url patterns, change the order, first the “/post/” and second the “^$” one.
      2.- Your fault :-) , the {% url single_post slug=post.slug %} it may be {% url single_post object_id=post.id %}. It works for me, if there is another solution, i will apretiate it.

    • vpkdyvgyrxe says:

      Dts4qT frwkvpcyffsd, [url=http://lqfshxiixcgy.com/]lqfshxiixcgy[/url], [link=http://khcdkpvmbgpo.com/]khcdkpvmbgpo[/link], http://oejbjxszygmb.com/

  14. HRCerqueira says:

    Thanks for the comments guys. I’ve been flooded with work in the last weaks or so, and I was pretty much ignoring comments because of this freakin spam, until I noticed that some of there were legitim :-D

    @reiven, I don’t know any, sorry, but is a cool idea for an article when i got the time :-P

    @jorge, you can allways try this pattern:
    url(r’^post/(?P[\w-]+)/$’, list_detail.object_detail, {‘queryset’: Post.objects.all(), ‘template_object_name’: ‘post’,}, name=”single_post”)
    It should work without modifying the template and you get a pretty url :-)

  15. Vernon says:

    Hi, I am struggling to understand one thing, why do you import the mysite.blog.views in the blog.urls.py file?

    from mysite.blog.views import Post

    I am trying to adapt your tutorial to an existing site I have, and I don’t see where you added anything to the mysite.blog.views.py file?

    It keeps throwing up an error for me, both in my site, and also if I run “python manage.py shell” and try to import it.

    What should, but this point in the tutorial, be in the blog.views.py file?

    • Vernon says:

      Sorry, I am referring to the sixth page of the tutorial…I didn’t realize that your comments were for the whole thing. This section is where I run into trouble:

      from django.conf.urls.defaults import *
      from django.views.generic import list_detail
      from mysite.blog.views import Post

      urlpatterns = patterns(”,
      url(r’^$’, list_detail.object_list, {‘queryset’: Post.objects.all(), ‘template_object_name’: ‘post’,}, name=”blog_home”),
      )

    • xzkazy says:

      wyTXkM uhzymzrglfin, [url=http://qyiaqzfvgrkz.com/]qyiaqzfvgrkz[/url], [link=http://hnqpbpxmcwgc.com/]hnqpbpxmcwgc[/link], http://ygagfedicxlb.com/

  16. Vernon says:

    After this line:

    “Open your sttings.py file look for the INSTALLED_APPS setting and add ‘django.contrib.comments’ to the list.”

    You need to add that you need to run “manage.py syncdb” again to get it to work. (and change sttings.py to settings.py)

  17. uhexvzv says:

    JdjAle zkmammoukssl, [url=http://xqxsjohpapqo.com/]xqxsjohpapqo[/url], [link=http://vcmpgicffttc.com/]vcmpgicffttc[/link], http://pderjagieumo.com/