Monday, January 30th, 2012

Developing a website using Django

Before jumping into Python, I was developing websites using PHP. PHP is a wonderful scripting language, which tries to mimic a full scale language. Before I began learning Python, I took a close look at both Ruby and Python. I developed 2 similar applications which produce the same output to determine which language I would enjoy programming in more. I ended up picking up Python syntax much quicker, and therefore chose Python over Ruby. I still respect Ruby, especially for it's Ruby on Rails development. Without Ruby on Rails, Ruby wouldn't be as popular as it is now.

When I started using Python, I had no intent to replace PHP at the time. I was planning on developing desktop applications, utility scripts, and SDL applications. This is where I initially began to dive into Python. Once I began to use the language, I thought to myself, wouldn't it be great to create my websites using this language? I began to research on how to develop websites using Python. Since I was familiar with Apache and mod_php and rarely used any other server, my first search on google was mod_python. At this point, I never knew that Python had many web frameworks.

When I began Python website development, I was developing with the same habits I formed when I was developing with PHP. The logic was not separated fully from the templates, and a lot of my logic code was put into the PSP file, and all the code was not organized sanely. I developed a few websites using mod_python, and coded just like I was in PHP, with raw SQL and manually extracting and parsing queries from the GET and POST data. I forgot how I came to know about Python web frameworks and when I finally found Django, but finding out about the various web frameworks was one the best things that could happen to me.

I tried many web frameworks, and finally settled down with Django.

Learning Django was very easy thanks to it's really nice tutorial and documentation system. Deploying Django at first was a little confusing, but I found a good way that works with my needs. Because of how Django works, scaling it is very easy. Currently I have a 3 server configuration, one server runs nginx and my Django instance. Another server is for my database, and the final server is a CDN for all my static files and media. Even with a single server configuration and completely unoptimized code, Django still works quickly. I have heard many people in the Python community complaining about how slow the Django ORM is. For small sites it works just fine, even without caching. For larger sites, you will want to use caching regardless of what ORM you are using. If you do not properly use caching on a large scale website, you need to go back to school.

As you may have found out by this point in reading this post, this is not a tutorial on how to develop a website using Django. It is however, an introduction to me and how came into the world of Python and settled with Django. Thus why it is titled "Developing a website using Django".

Django comes with many tools to enable a web developer to create and deploy a website in a very small amount of time, a full featured website. You have have read many success stories of Django, and how quickly a website was built and deployed from scratching using it's technology. Django has a great page called DjangoResources with valuable links to various third party apps and full websites ready to be deployed using Django. I highly recommend this resource.

One reason I wanted to create my blogging software from scratch is, I wanted to use the Django template system in my entries themselves. All existing blogging software out there uses some other markups, or even pure HTML. I thought that since the Django template system is so powerful and that I can essentially create custom tags and filters, that why not just write my blog entries using it? Well, that is exactly what I did. The entries themselves are stored in the database. When the view is rendered, it takes the raw template code from the entry and displays it in the page. I ended up creating a template tag called render_as_template, which I can use in a template to render a string of data. Caching of this information has not yet been enabled, but this is my next goal. I am not expecting a large amount of viewers on this blog when I first bring it up live. As the months go by, this may change and caching will need to be used in order to make sure the website does not slow down considerably. I have template tags for both rendering of images and bookmarks from the database. The more I use these tags in an entry, the more the database is going to be hit. This is not at all good for performance, and thus why caching will soon be enabled.

This is my first actual blog post on the website, so I wanted to go more for an introduction to how I got into Python and my history of using it. Please feel free to leave any comments below on your thoughts, and if you would use Python for website development or not.

Comment #1: Posted 2 years, 7 months ago by Thomas

Hi Kevin,

Interesting article, thanks!
I also wrote an article about the differences between Python and Ruby, but not from a GUI development perspective rather than a web development perspective:
http://www.dallagnese.fr/computers-it/python-vs-ruby-through-a-concrete-example/

My conclusions are a bit different as I find more pleasant developing in Ruby, although I mostly develop in Python...

Regarding Django, I think it's a wonderful framework and use it myself.
I have intensively tried another Python framework: web2py, which is even more promising. However, web2py lacks support and documentation where Django has plenty of it, so I recently migrated to Django.

Good luck with your Django website.

Cheers,

Thomas

About Me

My Photo
Names Kevin, hugely into UNIX technologies, not just Linux. I've dabbled with the demons, played with the Sun, and now with the Penguins.




Kevin Veroneau Consulting Services
Do you require the services of a Django contractor? Do you need both a website and hosting services? Perhaps I can help.

This Month

If you like what you read, please consider donating to help with hosting costs, and to fund future books to review.

Python Powered | © 2012-2014 Kevin Veroneau