settings.py

作者:上海建筑防水有限公司  来源:www.yxjzfs.com   发布时间:2017-09-05 12:30:51
settings.py In settings.py:

HERE=os.path.dirname(os.path.dirname(__file__)

MEDIA_ROOT=os.path.join( HERE , 'media').replace('\\','/')

MEDIA_URL = '/media/'

STATIC_ROOT =os.path.join( HERE , 'static').replace('\\','/')

STATIC_URL= '/static/'

ADMIN_MEDIA_ROOT = '/static/admin/'

STATICFILES_DIRS = (

os.path.join(HERE,'app1/static/').replace('\\','/'),

os.path.join(HERE,'app2/static/').replace('\\','/')

)

In urls.py add these codes:

from django.conf import settings

from django.conf.urls.static import static

urlpatterns += static(settings.MEDIA_URL , document_root = settings.MEDIA_ROOT )

urlpatterns += static(settings.STATIC_URL, document_root = settings.STATIC_ROOT )

in templates:

{% load static %}www.2cto.com

<img src="{{ get_static_prefix }}images/1.jpg" />

<link href="{{ get_static_prefix }}css/truple.css />

很重要的几段话:

1.# Don't put anything in this directory(STATIC_ROOT) yourself; store your static files in apps' "static/" subdirectories and in STATICFILES_DIRS.

2.The most likely example is user-uploaded content in MEDIA_ROOT. staticfiles is intended for static assets and has no built-in handling for user-uploaded files, but you can have Django serve your MEDIA_ROOT by appending something like this to your URLconf:

urlpatterns += static(settings.MEDIA_URL , document_root = settings.MEDIA_ROOT )

,,

企业建站2800元起,携手武汉肥猫科技,做一个有见地的颜值派!更多优惠请戳:武汉网站建设公司 https://www.jingchucn.com/zt/wuhan_wangzhanjianshe/


上一篇:如何找到销售不利原因所在?客服电话也可以追踪分析
下一篇:最后一页