Question

I've developed many applications using the MVC pattern in Zend and Symfony. Now that I'm in Pythonland, I find that many frameworks such as Flask, Django and Pyramid use a file called views.py to contain functions which implement the routes. But, these "views" are really controllers in other MVC frameworks I've used before. Why are they called views in Python web frameworks? And, can I change them to controller.py without tearing a hole in the Python universe?

Était-ce utile?

La solution

A view, from the django's perspective is what content is presented on a page. And the template is the how it is presented.

A django view is not exactly a controller equivalent. The controller in some of those other frameworks is how the call of a function happens. In django, that is a part of the framework itself.

Technically, there is nothing preventing you from renaming your views into controllers.- The URL routing scheme takes either the function or the string to the function. As long as you can send the appropriate string to the function (or the function itself), you can call your view whatever you want. However, for the reason stated in the paragraph above and for the fact of meeting the expectations of the other people that work on django, you should not really have files called controller.py.

It's just a matter of getting used to. Hang in there for a bit.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top