jdango结构
路由里加入各种路径
记得头部加入from django.conf.urls import url, include
不然url无法识别

view文件内渲染静态文件

点击查看代码
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [BASE_DIR / 'templates'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
静态文件放在templates内,static内放css,js

静态文件内引用
点击查看代码
{% block css %}
<link rel="stylesheet" href="/static/plugin/bootstrap-3.4.1-dist/css/bootstrap.css">
<link rel="stylesheet" href="/static/plugin/bootstrap-3.4.1-dist/css/bootstrap-theme.min.css">
<link rel="stylesheet" href="/static/plugin/bootstrap-3.4.1-dist/css/bootstrap-theme.min.css.map">
{% endblock %}
{% block css_and_js %}
<script src="/static/plugin/bootstrap-3.4.1-dist/js/bootstrap.min.js" language="JavaScript"></script>
<script src="/static/plugin/bootstrap-3.4.1-dist/js/npm.js" language="JavaScript"></script>
<script src="/static/js/jquery211.min.js"></script>
{% endblock %}
setting内配置
点击查看代码
STATIC_URL = '/static/'
STATICFILES_DIRS = [
# static为项目路径下你存放静态文件的文件夹的实际路径
os.path.join(BASE_DIR, 'static')
]
路由的匹配
url(r'index$', DataFix.views.index),
url(r'^excel/import/index$', DataFix.views.excelIndex),
原因是第一个是模糊匹配,结尾是index就渲染第一个,需要加上“^”

浙公网安备 33010602011771号