python - 比较一下Django的url配置和Flask的url配置哪个好一些?
ringa_lee
ringa_lee 2017-04-17 17:58:11
0
2
478

打算基于Tornado设计一个简单的Web框架扩展,改造一下url编写方式,我比较喜欢Flask的url配置,通过一个装饰器来设置视图函数的url,但是这么配置有一个问题,

|- app +- dir | |- views | |- hello_view.py | |- world_view.py | |- ...

像以上的模块结构,那么应用启动加载url前需要先加载各个视图模块。

大家觉得两种url配置方式各有什么优劣呢?装饰器注册url的方式需要先加载各种视图模块有没有什么好的解决方式?

ringa_lee
ringa_lee

ringa_lee

reply all (2)
洪涛

First of all, the style of Flask is based on frameworks such as SpringMVC, which uses decorators for routing. Take Java as an example

@Controller @RequestMapping("/") public class Index { @RequestMapping(method = RequestMethod.GET) public String index() { System.out.println("index called"); return "index"; } }

SpringMVC has been used in many commercial applications, so there is a market for this loose routing model.
Django has learned from the DRY principle (Don’t repeat yourself (DRY)) of Rails, so the default is more preferable to the configuration.

From the perspective of routing, I personally feel that Django is more flexible. If you are familiar with regular expressions, it is easy to change the routing of a URL, but it is a little troublesome in flask.

From a practical perspective, Django is heavier, Flask is lighter, Django performance is worse, Flask is better, Django documentation is better, Flask is worse, many people complain that Django ORM is terrible, Flask uses sqlalchemy by default, which is basically the standard of python ORM .

Anyway, each has its own merits. It’s hard to say which method is better in terms of Url routing. It depends on personal habits.

    大家讲道理

    Personally, I think it depends on the size of the website. If the website is small, the two are similar.Flask优雅点,但是网站规模大了,一定是Django’s centralized routing management is better.

      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!