skip to Main Content

127.0.0.1/:1 Refused to execute script from 'http://127.0.0.1:8000/scripts/scripts.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.

error i got…

how do i even fix this?
i have generated a template from django and they look messy so i want to organise files like .css files and pages files…

i tried to add my .css file and routed the html to use this .css. later i discovered that i gotta add
{% load static %} to load static files i have added this too and still not working….

this s the image guys

in the image i made a styles folder and wanted to use that but not the site.css file, i think i need to edit some things in the settings.py can you guys instruct me?

2

Answers


  1. Please add this to setting.py file and try again.

    import mimetypes
    
    mimetypes.add_type("text/javascript", ".js", True)
    
    mimetypes.add_type("text/css", ".css", True)
    
    Login or Signup to reply.
  2. For http://127.0.0.1:8000/scripts/scripts.js:-
    Could you try to visit the URL from your browser and check whether the file is loading? You can also debug through developer’s tools in your browser, click F12, and go to the Network tab.

    For styles.css:-
    Could you add this to your settings.py file?

    STATIC_URL = '/static/'
    STATICFILES_DIRS = [
        BASE_DIR / "static",
    ]
    

    Now, if your file path is /static/somepath/styles.css
    You can easily access the file with this.

    {% load static %}
    
    #your code
    <a href="{% static 'somepath/styles.css' %}">Link</a>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search