Django:解决media、static和template路径问题
来源:互联网 发布:shtml nginx 编辑:程序博客网 时间:2024/06/06 19:40
将html文件加入到django路径有以下三步操作:
1、配置template路径
template路径用于存储.html文件
TEMPLATE_DIRS = ( os.path.join(os.path.dirname(__file__), '..', 'templates').replace('\\','/'), os.path.join('templates'),)
2、配置static路径
static路径用于存储.css .js .txt等静态文件
# Static files (CSS, JavaScript, Images)# https://docs.djangoproject.com/en/1.6/howto/static-files/STATIC_URL = '/static/'STATICFILES_DIRS = ( # Put strings here, like "/home/html/static" or "C:/www/django/static". # Always use forward slashes, even on Windows. # Don't forget to use absolute paths, not relative paths. os.path.join(os.path.dirname(__file__), '..', 'static').replace('\\','/'), os.path.join('static'),)
配置static路径的绝对路径
# Absolute path to the directory static files should be collected to.# Don't put anything in this directory yourself; store your static files# in apps' "static/" subdirectories and in STATICFILES_DIRS.# Example: "/home/media/media.lawrence.com/static/"STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static')
3、配置media路径
media路径用于存储.jpg .mp4等用户上传的文件
import osPROJECT_ROOT = os.path.realpath(os.path.dirname(__file__))# Absolute filesystem path to the directory that will hold user-uploaded files.# Example: "/home/media/media.lawrence.com/media/"MEDIA_ROOT = os.path.join(PROJECT_ROOT, 'media')# URL that handles the media served from MEDIA_ROOT. Make sure to use a# trailing slash.# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"MEDIA_URL = '/media/'
为了能够访问media路径,需要在url中设置
from django.conf import settingsfrom django.conf.urls.static import staticif settings.DEBUG: # static files (images, css, javascript, etc.) urlpatterns += patterns('', (r'^media/(?P<path>.*)$', 'django.views.static.serve', { 'document_root': settings.MEDIA_ROOT}))
注意:url(r'^','views.action')会导致media无法访问,因为没有加$截止url
0 0
- Django:解决media、static和template路径问题
- Django static media template目录设置方法
- Django中static、media与template设置
- Django Template 路径配置
- django 之设置media static
- 在Django中计算出你的项目中的template dir和media dir
- tango with django ch5 template&static file
- Django settings.py 的media路径设置
- Django settings.py 的media路径设置
- Django settings.py 的media路径设置
- django模版路径问题
- urllib unquote 在django template上面问题
- django静态文件static路径配置
- 在Django里面加载static路径
- django静态文件(static)路径配置
- Django中程序中图片资源的路径问题(static文件夹的放置)
- 第五章 模版和Static Media
- Django template
- 系统设置 设置项 丢失
- POJ 1088 滑雪 DFS 记忆化搜索
- 找出最大的数并统计个数
- USACO 2.3.4 Money Systems
- 求二元查找树的镜像
- Django:解决media、static和template路径问题
- 什么是DOM
- Bcm6816uni_dspdd.doc
- Struts2 用 s:if test 判断属性和字符串相等时 注意双引号和单引号的使用
- css3阴影趣味详解
- 反转单链表
- HDU1114 Piggy-Bank 【完全背包】
- KERNEL_Makefile.modpos.doc
- 针对<mvc:annotation-driven />xml出现错误时,做如下修改可以将xml前面的红叉去掉