Django 学习笔记

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 

你可能感兴趣的:(Django 学习笔记)