本文共 4847 字,大约阅读时间需要 16 分钟。
django flask
I spent Saturday on rewriting a Flask app in Django. The app in question was , which is a very simple CRUD app. And yet, the Flask code was a mess, full of bugs and vulnerabilities. Eight hours later, I had a fully functional Django app that did more and fixed all problems.
我花了星期六在Django中重写Flask应用。 有问题的应用程序是 ,这是一个非常简单的CRUD应用程序。 但是,Flask代码是一团糟,充满了错误和漏洞。 八个小时后,我有了一个功能齐全的Django应用程序,它可以执行更多操作并解决了所有问题。
The original Flask app had a ton of problems. In order to make it anywhere near useful, I would need to spend hours. Here’s just a few of them:
最初的Flask应用存在很多问题。 为了使它几乎有用,我需要花费数小时。 这里只是其中的一些:
I started the process by opening , with its wonderful . Now, I have written a couple basic Django apps before, but the majority of them didn’t do much. In other words, I didn’t have a lot of experience. Especially with taking user input and relationships. It took me about 8 hours to get feature parity, and more.
我通过打开及其出色的开始了这一过程。 现在,我之前已经写了几个基本的Django应用程序,但是其中大多数并没有做很多事情。 换句话说,我没有很多经验。 特别是在获取用户输入和关系时。 我花了大约8个小时来获得功能对等,还有更多。
Getting all the features was really simple. For example, to get a many-to-many relationship for languages, I had to write just one line.
获得所有功能非常简单。 例如,要获得语言的多对多关系,我只需要写一行。
languages languages = = modelsmodels .. ManyToManyFieldManyToManyField (( LanguageLanguage ))
That’s it. I didn’t have to run through complicated SQLAlchemy documentation, which provides a to the same problem.
而已。 我不必遍历复杂SQLAlchemy文档,该文档提供了针对同一问题的 。
Django also simplified New Relic integration, as the browser JS can be implemented using Django template tags.
Django还简化了New Relic集成,因为可以使用Django模板标签实现浏览器JS。
Django is not without its problems, though. I got a very cryptic traceback when I did this:
但是,Django并非没有问题。 当我这样做时,我得到了一个非常隐秘的回溯:
The real problem with this code? I forgot the label= keyword. The problem is, the model API accepts this syntax — verbose_name is the first argument. (I am not actually using the labels though, I write my own form HTML)
这段代码的真正问题是什么? 我忘记了label =关键字。 问题是,模型API接受此语法-verbose_name是第一个参数。 (尽管我实际上并未使用标签,但我编写了自己的表单HTML)
Still, the Django version is much cleaner. And the best part of all? There are no magic global objects (g, session, request) and decorator-based views (which are a bit of syntax abuse IMO).
不过,Django版本要干净得多。 而最好的部分呢? 没有魔术全局对象( g , session , request )和基于装饰器的视图(IMO有点语法滥用)。
In the end, I have:
最后,我有:
CSRF_ENABLED variable, but it did not seem to be actuallyCSRF_ENABLED变量,但实际上似乎不是 used by anything. 被任何东西使用。 |
翻译自:
django flask
转载地址:http://qvqwd.baihongyu.com/