您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

python – Django和MVC(MVT)布局

5b51 2022/1/14 8:21:57 python 字数 3105 阅读 499 来源 www.jb51.cc/python

我来自使用其他基于MVC的框架,并进入Django,它似乎有点尴尬我以前.例如,在其他基于MVC的框架中.我的布局可能是这样的:root: - config (houses the config files (like settings), url.conf, db connections, etc.) - controllers (houses the m

概述

我来自使用其他基于MVC的框架,并进入Django,它似乎有点尴尬我以前.例如,在其他基于MVC的框架中.我的布局可能是这样的:

root:
- config (houses the config files (like settings),url.conf,db connections,etc.)
- controllers (houses the main logic of each section of the site. The middle ground between views and models)
- models (handles all the data to be validated and anything that interacts with the database. declares the DB structure. each model a class,each attribute a db field. in django,a template?)
- views (the html displayed to the end user,put together by the controllers)
- tests (all the tests)
- plugins (3rd party apps you install into yours.)
- uploads (user uploaded files)
- public_html (the actual public facing files)
-\ css|js|img (the varIoUs static file types for page manipulation)
-\ index.html

这就是我习惯的,似乎django做的事情有很大的不同.以前,如果我有一个投票应用程序,我会:

controllers/PollController.py
models/Poll.py
views/poll/index.py

这将在db中创建poll表.但在Django,我该怎么做?这是一个可接受的布局吗?从我所读到的,上面将更像是这样:

root:
- project (this would be the main app,and what glues everything together)
--/ settings.py
--/ urls.py
--/ templates/

- apps
-/ Poll
--/ models.py (i would have no Poll.py model,so it would all go in here)
--/ urls.py (any url.conf specific to this model would go in here)
--/ templates/ (the varIoUs views for this app)

虽然这在某些方面确实有意义,但它对我来说感觉很陌生.与第一个示例中描述的传统mvc布局相比,这种布局有什么好处吗?除此之外还有另一种首选布局吗?这个“项目”的目的是核心将是我自己使用的基本框架,我将为每个使用此框架创建一些不同的“应用程序”.在旧版本中,每个应用程序只会通过成为该目录中的插件来扩展主要应用程序.

作为背景说明,我的大多数经验都是在PHP和各种框架中(如大多数情况下,这些),如果这会产生影响.这将是我在python / django中的第一个主要项目.我只是想做对.

如果你认为一个网站是一个由几个个体和大多数不同的“应用程序”集合在一起的想法,并用一些粘合剂将它们组合在一起,那么这个组织就更有意义了.

总结

以上是编程之家为你收集整理的python – Django和MVC(MVT)布局全部内容,希望文章能够帮你解决python – Django和MVC(MVT)布局所遇到的程序开发问题。


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶