Django 学习笔记
2019-04-25 本文已影响0人
Fonzie
Django 处理静态文件
- 先在
项目的/setting.py
文件中配置如下:
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
]
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
- 创建项目,并创建urlspatterns,效果如下:
from django.urls import path
from . import views
from django.conf.urls.static import static
from django.conf import settings
urlpatterns = [
path('', views.index, name='index'),
path('deploy/', views.deploy_record, name='deploy_record'),
path('api/build/', views.deploy_save_as, name='api_build'),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
- 收集静态资源
python manage.py collectstatic