<p>Im来自于使用其他基于MVC的框架,而进入Django,对于Im过去的做法似乎有点尴尬。例如,在其他基于MVC的框架中。我的布局可能是这样的:</p>
<pre><code>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
</code></pre>
<p>这就是我过去的习惯,看起来django做的事情很不一样。以前如果我有一个投票应用,我会有:</p>
<pre><code>controllers/PollController.py
models/Poll.py
views/poll/index.py
</code></pre>
<p>这将在数据库中创建poll表。但在Django,我该怎么做?这个布局可以接受吗?从我所读到的内容来看,上面的内容更像是这样:</p>
<pre><code>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)
</code></pre>
<p>虽然这在某些方面是有道理的,但它只是让我觉得陌生。与第一个示例中描述的传统mvc布局相比,这种布局有什么好处吗?除此之外还有其他首选布局吗?这个“项目”的目的是,核心将是一个基本框架,供我自己使用,我有几个不同的“应用程序”,我将为每个使用这个框架创建。在旧版本中,每个应用程序只是通过作为该目录中的插件来扩展主应用程序。</p>
<p>作为一个背景说明,我的大部分经验是在php和来自那个worls的各种框架(cakephp,yii,主要是),如果这有什么不同的话。这将是我在python/django中的第一个主项目。我只想把事情做好。</p>