Django
プロジェクトの構造
サーチ…
リポジトリ>プロジェクト>サイト/会議
ソース管理下のrequirementsとdeployment tools備えたDjangoプロジェクト用。この例は、Djangoの2つのスクープからの概念に基づいています。彼らはテンプレートを公開しています:
repository/
docs/
.gitignore
project/
apps/
blog/
migrations/
static/ #( optional )
blog/
some.css
templates/ #( optional )
blog/
some.html
models.py
tests.py
admin.py
apps.py #( django 1.9 and later )
views.py
accounts/
#... ( same as blog )
search/
#... ( same as blog )
conf/
settings/
local.py
development.py
production.py
wsgi
urls.py
static/
templates/
deploy/
fabfile.py
requirements/
base.txt
local.txt
README
AUTHORS
LICENSE
ここで、 appsフォルダとconfフォルダには、 user created applicationsとプロジェクトのcore configuration folderがそれぞれ含まuser created applications 。
projectディレクトリ内のstaticおよびtemplatesフォルダには、 project全体でグローバルに使用されている静的ファイルとhtml markupファイルが含まれています。
また、すべてのアプリケーションフォルダのblog 、 accounts 、 searchは、 staticフォルダとtemplatesフォルダが(ほとんど)含まれてstaticあります。
djangoアプリケーション内の静的ファイルとテンプレートファイルの名前空間
staticおよびtemplatesフォルダには、アプリ名のフォルダが含まれている必要がありますex. blogこれは名前空間の汚染を防止するために使用される規則ですので、我々は次のようにファイルを参照/blog/base.htmlではなく/base.html我々が参照し、名前空間を保持しているファイルの詳細明快さを提供します。
例: blogやsearchアプリケーション内のtemplatesフォルダには、名前がbase.htmlファイルが含まれています。 viewsファイルを参照すると、アプリケーションはどのファイルをレンダリングするのか混乱します。
(Project Structure)
.../project/
apps/
blog/
templates/
base.html
search/
templates/
base.html
(blog/views.py)
def some_func(request):
return render(request, "/base.html")
(search/views.py)
def some_func(request):
return render(request, "/base.html")
## After creating a folder inside /blog/templates/(blog) ##
(Project Structure)
.../project/
apps/
blog/
templates/
blog/
base.html
search/
templates/
search/
base.html
(blog/views.py)
def some_func(request):
return render(request, "/blog/base.html")
(search/views.py)
def some_func(request):
return render(request, "/search/base.html")
Modified text is an extract of the original Stack Overflow Documentation
ライセンスを受けた CC BY-SA 3.0
所属していない Stack Overflow