在Django应用程序(1.7)中,文件夹的最佳结构(最佳实践)是什么?我不确定将静态数据和文件上传放在何处。
在我所有的项目中,结果都不同,但是目前我有类似的东西(我遗漏了一些明显的文件夹/文件):
project/
bin/
include/
...
src/
manage.py
main/
- settings.py
- urls.py
signup/
static/
static_/
+ css
+ img
+ js
static/
templates/
- index.html
- base.html
- ...
uploads/
而且,我更希望例如以urlsite.com/css/file.css
代替site.com/static/css/file.css
,但以某种方式比看起来要复杂。怎么能做到呢?
我在setting.py
(目前使用Django v1.6.8)中使用以下内容
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
#TEMPLATE_DIRS = (os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), "static", "templates"),)
TEMPLATE_DIRS = (
os.path.join(BASE_DIR, 'templates'),)
这给了我一个文件夹布局
project/
manage.py
project_app/
- settings.py
- urls.py
someother_app/
- admin.py
- models.py
- views.py
static/
css/
javascript/
templates
admin/
someother_app/
- base.html
- index.html
media/
我不确定你说的是什么意思site.com/css/file.css
。喜欢的东西<link rel="stylesheet" href="{{ STATIC_URL }}css/jquery.asmselect.css">
在<head>
的base.html
用途Django框架出示您的.css文件。为什么不使用那里的东西呢?节省时间和精力。
汤米
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句