Archive for the ‘Django’ Category
It’s surprising that in our blog we have never written about Python frameworks and Python itself either. So, I’ve decided to help out the omission :)
When choosing a framework for site development you have many things to consider. If the criterion is a programming language, for Microsoft and C# followers the choice is clear – ASP.NET. Those who are in love with Ruby don’t have to think too much either – Ruby on Rails will be their choice. It’s much more complicated for Python, PHP and Java developers to make up their mind: the quantity of frameworks here is tremendous.
Firstly, I want to underline the pluses of Python frameworks in general:
- Usage of Python language. I’m sure lots of programmers are pretty tired of praising Python. But to write a site on Python is really faster, cheaper and more pleasantly than on other languages.
- Wide choice. Frameworks abundance can be scaring only for beginners. A professional always welcomes the freedom of choice, as the chance to find what you really need only increases. Besides, choice entails competition, and healthy competition leads to quality improvement of every framework.
- Rapid development. New frameworks emerge constantly, and their precursors either give their way to the younger ones, or continue their struggle for leadership: bugs are fixed, new features are implemented. It differentiates Python community from, Ruby community, for instance, which is represented mostly by Ruby on Rails. Due to the lack of new ideas we can see some standstill in Ruby on Rails development.
- Opensource. They say using quality software on a legal and free basis is really cool :)
For now there are several dozens of Python frameworks. Among them are famous Django, Pylons, Turbogear, and some other interesting ones, as Zope, Twisted, CherryPy.
Today I want to make a short review of the more popular Python framework – Django.
Django was created specially for convenient news site development of The World Company. It had been developed since 2000, but to the general public it was presented only in the middle of 2005. The framework got its name after a Belgian jazz guitarist and composer Django Reinhardt.
Django site is built from one or several applications, which are recommended to be made alienable and interconnected (unlike Ruby on Rails, for example). One of the main Django advantage is excellent documentation, and, I suppose, the biggest community among all the Python frameworks.
When getting acquainted with Django, firstly, his built-in administrator interface wins over. It provides convenient work with the content of a written site. You should change the settings a little bit, then following the link http://127.0.0.1:8000/admin you can start the page through which it is easy to manage the content (for example, to look through the data base content and change it).
Django architecture is a bit different from classic MVC. Controller of the classic model MVC approximately corresponds the level, which is called “View” in Django. Presentation View logic is realized on the level of Templates. Due to this Django level architecture is frequently called “Model-Template-View” (MTV).
For models Django provides an abstraction level which frees from the necessity of writing SQL-requests for getting/saving data to the database. All the tables, that are used in the application, are written as classes in a separate file models.py. Then with the help of these classes methods there happens manipulation of the tables content in the code. Thus, work with database becomes fully object-oriented. Django supports work with the main databases (PostgreSQL, SQLite3, MySQL, Oracle).
Also, it is worth noting about a very flexible way of urls reflection on the application function – with the help of regular expressions.
While developing an application it is convenient to use built-in server. It automatically determines the changes in the files of the project source code and reboots. The result from changes made to the code immediately displays on a browser web-page, but it is not recommended to use it as a working one, as it is single-threaded and do not provide any security measures. For these purposes you will have to set a normal server (Apache, for example).
To be honest till the very end, I will enumerate Django disadvantages as well:
- Though the template language is simple, still it is not very “pythonic”
- Not very convenient work with AJAX
- There can emerge some difficulties while replacing components (if you are in bad relations with regular expressions, which are used widely in urls reflection, you may want to use another dispatcher). It is widely believed that Django developers quite often invent bikes. Though Django allows doing this easily and quickly.
Although Django is one of the most popular Python frameworks, do not forget that framework is just an instrument; the choice should depend on the task set firstly, and only after that on its popularity.
Thank you for consideration. As usual, I would be happy to see your comments :)