[Python] 404 Static file not found - Django

Discussão em 'Python' iniciado por Stack, Março 3, 2025.

  1. Stack

    Stack Membro Participativo

    I have an issue with django. I recently bought an instance of a shared server and I wanted to move my django website from AWS to this server (which use Cpanel). All worked fine with AWS but when I switched to Cpanel all statics files were missing.

    this is my settings.py:

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

    MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
    MEDIA_URL = "/media/"

    STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static'),
    ]


    my project structure:

    my_project
    |-app/
    |-...
    |-views.py
    |-db.sqlite3
    |-manage.py
    |-media/
    |-my_project/
    |-...
    |-settings.py
    |-static/
    |-main_page/
    |-js/
    |-my-script.js


    I add static files like this:

    {% load static %}
    <script src="{% static 'main_page/js/my-script.js' %}"></script>



    This is the error:

    GET http://my.domain.com/static/main_page/js/my-script.js net::ERR_ABORTED 404 (Not Found)


    When I go to the URL of the file it understands it like one of my URLs:

    [​IMG]

    I hope you will help me to solve this issue ;) thanks.

    Continue reading...

Compartilhe esta Página