Django 停止更新静态文件

问题描述 投票:0回答:1

Django不上传静态文件

嘿伙计们,我来找你们是因为我有一个无法解决的问题。我在本地主机上,尽管文件已更改,但 Django 不会应用我对静态文件所做的修改。

所以从这里开始我到目前为止所做的事情:

  • 清除浏览器缓存
  • 重启服务器
  • 最佳答案的步骤1和2:stackoverflow.com/questions/27911070/django-wont-refresh-staticfiles
  • 更换浏览器
  • 删除pycache文件

似乎没有任何效果,如果您能解释如何解决此问题,但主要是为什么会发生这种情况,那就太好了! 😊

PS:

我在模板末尾引用了我的脚本:

    <script type="module" src= "{% static 'homepage/APICalls.js' %}?version=1"></script>
{% endblock content %}

包含 200 代码的 URL 返回过时的代码:

[06/May/2024 15:48:20] "GET /statico/homepage/APICalls.js?version=1 HTTP/1.1" 200 1987

静态文件设置:

STATIC_URL = 'static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

文件结构:

C:.
│   db.sqlite3
│   manage.py
│
├───homepage
│   │   admin.py
│   │   apps.py
│   │   credentials.py
│   │   get_jahia_json.py
│   │   models.py
│   │   permissions.py
│   │   serializers.py
│   │   setter.json
│   │   tests.py
│   │   views.py
│   │   __init__.py
│   │
│   ├───migrations
│   │   │   
│   │   │
│   │   └───__pycache__
│   │           
│   │
│   ├───static
│   │   └───homepage
│   │           add-icon.svg
│   │           APICalls.js
│   │           comparison_page.css
│   │           content_menu.css
│   │           custom.css
│   │           functions.js
│   │           modifications_page.css
│   │           module_page.css
│   │           module_table.css
│   │           navbar.css
│   │           Neo_Sans_Pro_Bold.woff2
│   │           Plateformepage.css
│   │           responsive.css
│   │           responsive_module.css
│   │           responsive_navbar.css
│   │           responsive_plateforme.css
│   │           Roboto-Regular.woff2
│   │           searchbar.css
│   │           toggle.css
│   │           toggles.js
│   │           unicorn.css
│   │
│   ├───templates
│   │   └───homepage
│   │           all_modifs.html
│   │           base_test.html
│   │           comparison_page.html
│   │           homepage.html
│   │           homepage_test.html
│   │           module_page.html
│   │           Plateformes.json
│   │           plateforme_page.html
│   │           _modal.html
│   │           _modif.html
│   │           _module.html
│   │           _Plateforme_bloc.html
│   │           _Plateforme_bloc_test.html
│   │           _toggle.html
│   │           _version.html
│   │
│   └───__pycache__
│          
│
├───module_monitoring
│   │   asgi.py
│   │   settings.py
│   │   urls.py
│   │   wsgi.py
│   │   __init__.py
│   │
│   └───__pycache__
│           settings.cpython-310.pyc
│           urls.cpython-310.pyc
│           wsgi.cpython-310.pyc
│           __init__.cpython-310.pyc
│
└───static
    ├───admin
    │   ├───css
    │   │   │  
    │   │   │
    │   │   └───vendor
    │   │       └───select2
    │   │               
    │   │
    │   ├───img
    │   │   │   
    │   │   │
    │   │   └───gis
    │   │           
    │   └───js
    │       │   
    │       │
    │       ├───admin
    │       │      
    │       │
    │       └───vendor
    │           ├───jquery
    │           │      
    │           │
    │           ├───select2
    │           │   │   
    │           │   │
    │           │   └───i18n
    │           │           
    │           │
    │           └───xregexp
    │                   
    │
    ├───homepage
    │       add-icon.svg
    │       APICalls.js
    │       comparison_page.css
    │       content_menu.css
    │       custom.css
    │       functions.js
    │       modifications_page.css
    │       module_page.css
    │       module_table.css
    │       navbar.css
    │       Neo_Sans_Pro_Bold.woff2
    │       Plateformepage.css
    │       responsive.css
    │       responsive_module.css
    │       responsive_navbar.css
    │       responsive_plateforme.css
    │       Roboto-Regular.woff2
    │       searchbar.css
    │       toggle.css
    │       toggles.js
    │       unicorn.css
    │
    └───rest_framework
        ├───css
        │
        │
        ├───docs
        │   ├───css
        │   │       
        │   │
        │   ├───img
        │   │      
        │   │
        │   └───js
        │           
        │
        ├───fonts
        │       
        │
        ├───img
        │       
        │
        └───js
python django django-staticfiles
1个回答
0
投票

注意,您的日志中有一些奇怪的东西:

"GET /statico/
!=
STATIC_URL

在主页应用程序中,您有不寻常的文件夹结构:

homepage/templates/homepage
模板的推荐结构,但对于静态文件,您不需要在
/homepage
下额外的子文件夹
homepage/static
。将文件从
homepage/static/homepage
移动到
homepage/static
,再次运行
collectstatic

© www.soinside.com 2019 - 2024. All rights reserved.