3 ms·
"Django really likes to constrain users here - not even letting them use a full "if" statement." Yes, but as you've noted it's for a good reason. This is reall
by ubernostrum 17y ago
"Django really likes to constrain users here - not even letting them use a full "if" statement."
Yes, but as you've noted it's for a good reason. This is really one of the few places where Django gets opinionated by default, and personally I'm OK with that; keeping people off the slippery slope of "well, I should write this in a cleaner way, but for now I'll just stuff some application logic in the template and fix it later" is a goal I can get behind.
"The author suggests that you can use models from different applications in Django. That sounds cooler than it is. They're all running off the same database and in the same project."
Not really. I can have multiple different Django "projects", each running its own settings, its own database, its own URL configuration, its own templates, etc., but all using the same single copy of an application module somewhere on the server. Last I checked this was non-trivial to do in Rails, while in Django it's made very easy since it's a common use case, and encourages neatly abstracting/encapsulating common pieces of functionality for reuse.
"The Django folk say that it takes very little time to write routes (true) and that one should be thoughtful when making URLs (also true). But sometimes it just feels tedious. Really, it's just a matter of preference."
Personally, I tend to view this more as a security concern than a programmer-convenience concern; if my framework is auto-mapping URLs to any code it can find, it may auto-map some things that I didn't want to expose (this was the source of an exploitable vulnerability in Rails a while back, as you may remember). If the framework only handles the URLs I tell it to handle, I don't get that situation.
Mostly, though, I like Django because it (and Python) fits my brain.
- mdasen 17y agoIf people don't agree on the IF statement, they just don't agree on it. I find that I can discipline myself enough to use a full IF - having always used the pyif (http://www.djangosnippets.org/snippets/130/ http://www.djangosnippets.org/snippets/130/) template tag in Django. I don't think this is such a big deal since one can swap out the templating layer in both Django and Rails for something they'd rather. If anyone reading this sees this as a big point, Liquid in Rails offers a more Django-like experience and Cheetah will give you things like full IFs in Python. You make a good point about not having to copy the code into the project directory and have multiple pieces of code sitting on the server. Someone pointed out that Rails Engines (included in 2.3) allow for this, but I haven't personally used them to know how nicely they work. For the security concern of auto-routes, this is actually a bigger concern in Python than in Ruby just because of the different ways that they handle OO stuff. In Python, everything is a public method. So, if Django just mapped URLs to methods, there would be no way of hiding a method you didn't want called. Ruby has the ability to make private and protected methods and Rails only makes public methods available as actions (the private and protected ones still being able to be called in their scope). So, it isn't a great security concern in Rails since it's trivial to define what is public and what isn't. Likewise, if one chooses, you can decide to map all of the URLs explicitly like Django and turn off the default :controller/:action/:id route. So, Rails offers both ways. Just as a note about Python: Django could just auto-map URLs to any method not starting with an underscore (the convention used in Python to say, this is kinda private even though Python will let you use it). Or there could be a kwarg (keyword argument) in the method signature that Django looked at. Anyway, there are ways around the fact that the Python language doesn't have explicitly private methods. Django's convention (like Python's) is just that explicit is better.
- ubernostrum 17y ago"If people don't agree on the IF statement, they just don't agree on it." Pretty much. And while individual cases can be argued, I think the general goal of keeping program logic out of templates is a good one. "For the security concern of auto-routes, this is actually a bigger concern in Python than in Ruby just because of the different ways that they handle OO stuff. In Python, everything is a public method. So, if Django just mapped URLs to methods, there would be no way of hiding a method you didn't want called." Actually, what I'm thinking of is a case where you might have a single application running on multiple sites, and -- for security reasons -- there'd be some views that you wouldn't want exposed on one or more of those sites. Forgetting to "un-map" even a single URL could lead to major problems (and, since an auto-mapping system can, in theory, locate anything that's on the import path, the risk seems to me to be a bit too much to accept just for the convenience of occasional automatic URLs).
- jamesbritt 17y ago"Yes, but as you've noted it's for a good reason. This is really one of the few places where Django gets opinionated by default, and personally I'm OK with that; keeping people off the slippery slope of "well, I should write this in a cleaner way, but for now I'll just stuff some application logic in the template and fix it later" is a goal I can get behind." Pretty sure Rails, via some plugin, lets you easily use Liquid templating in place of erb. Likewise for Ramaze and Merb. If you want constraints, they're easy to add.