Django中配置靜態文件夾static


1、在項目根目錄下創建 statics 目錄。

2、在 settings 文件的最下方配置添加以下配置:

STATIC_URL = '/static/' # 別名 STATICFILES_DIRS = [ os.path.join(BASE_DIR, "statics"), ]

3、在 statics 目錄下創建 css 目錄,js 目錄,images 目錄,plugins 目錄, 分別放 css文件,js文件,圖片,插件。

4、在模板中使用之前需要加入 {% load static %} 代碼,具體使用方式如下:

<!DOCTYPE html> <html lang="en"> <head> {% load static %} <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <link rel="stylesheet" href="{% static 'libs/bootstrap/css/bootstrap.min.css' %}"> <link rel="stylesheet" href="{% static 'libs/toastr/css/toastr.css' %}"> <link rel="stylesheet" href="{% static 'libs/bootstrap-table-master/bootstrap-table.css' %}"> <script src="{% static 'libs/jquery/jquery-1.11.2.min.js' %}"></script> <script src="{% static 'libs/bootstrap/js/bootstrap.min.js' %}"></script> <script src="{% static 'libs/toastr/js/toastr.min.js' %}"></script> <script src="{% static 'libs/bootstrap-table-master/bootstrap-table.js' %}"></script> <script src="{% static 'libs/bootstrap-table-master/locale/bootstrap-table-zh-CN.js' %}"></script> </head> <body> </body> </html>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM