django目录布局说明 [英] django directory layout explanation

查看:127
本文介绍了django目录布局说明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我刚刚创建一个django项目,名为coolprojectsite,目录结构如下所示:

  * media (dir)
* mytemplates(dir)
* * admin(dir)
* * coolprojects(dir)
* coolprojectsite(dir)
* * coolproject )
* * * __init__.py
* * * admin.py
* * * models.py
* * * tests.py
* * * urls。 py
* * * views.py
* * __init__.py
* * settings.py
* * urls.py
/ pre>

所以我有几个问题。



1)coolprojectsite被认为是项目 p>

2)coolproject被认为是应用程序



3)'media'包含css,javascript文件等这是他们适当的地方吗?它的外部项目。



4)'mytemplates'具有包含django标记(例如{%%})的特定文件,并且它们被访问,因为我的urls.py指向他们。将这些文件放在项目之外是否合适? 5)如果我想要包含一些任意的javascript文件(比如说jquery),那么我只需要在urls.py里创建一个新的条目(如果是的话,那应该是一个在coolprojectsite或coolproject),然后链接到该URL?

解决方案


  1. 项目Django并不是一个很有用的概念。 Django教程提到它,但是开发人员经常在邮件列表中提到他们希望他们没有介绍它。基本上,一个项目只是一个代码的容器,但实际上该代码可以生活在Pythonpath的任何地方。


  2. 是的,你可以有多个应用程序只要它们全部添加到settings.py中的INSTALLED_APPS。


  3. 他们住在哪里都没关系。您将需要一些服务 - 在开发中,可以使用内置的服务器完成,但在生产过程中,您需要直接将Apache(或任何)指向文件。


  4. 没关系。这是加载模板的视图,只要TEMPLATE_DIRS在settings.py中正确设置就行了。


  5. 不,绝对不是。如上所述,静态资产存在于您的媒体文件夹中,不能通过Django进行投放。



So I have a django project I just created called 'coolprojectsite' the directory structure looks something as follows:

* media (dir)
* mytemplates (dir)
* * admin (dir)
* * coolprojects (dir)
* coolprojectsite (dir)
* * coolproject (dir)
* * * __init__.py
* * * admin.py
* * * models.py
* * * tests.py
* * * urls.py
* * * views.py
* * __init__.py
* * settings.py
* * urls.py

So I have a few questions.

1) Is coolprojectsite considered the 'project'

2) Is coolproject considered the 'application'

3) 'media' contains the css, javascript files etc. Is that the proper place for them? Its outside the project.

4) 'mytemplates' has specific files that contain django markup (e.g. {% %} ) and they are accessed because my urls.py points to them. Is it proper to have these files outside the project?

5) If I want to include some arbitrary javascript file (say jquery) do I just create a new entry in urls.py (if so, should it be the one in coolprojectsite, or coolproject) and then link to that url?

解决方案

  1. "Project" is not really a useful concept in Django. The Django tutorial mentions it, but the developers have frequently mentioned on mailing lists that they wish they hadn't introduced it. Basically, a project is just a container for your code - but in fact the code can live anywhere on the Pythonpath.

  2. Yes, and you can have multiple applications as long as they're all added to INSTALLED_APPS in settings.py.

  3. It doesn't matter where they live. You will need something to serve them - in development, it can be done with the built-in server, but in production you'll need to point Apache (or whatever) directly at the files.

  4. Doesn't matter. It's the views that load the templates, and again as long as TEMPLATE_DIRS is set properly in settings.py that's fine.

  5. No, absolutely not. As mentioned, static assets live in your media folder, and don't get served through Django.

这篇关于django目录布局说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆