ashfaque jahan
ashfaque jahan

Reputation: 1

Refused to apply style from '<URL>' because its MIME type ('text/html') pythonanywhere

Refused to apply style from '' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

i dont have any problem in vscode but when i hosted into pythonanywhere i cant even login into admin panel and the css from admin panel is not working

Upvotes: 0

Views: 325

Answers (2)

mayursthakor
mayursthakor

Reputation: 1

The issue lies in the configuration of the application, as it states it does required full path of the file rather than sort path. I was looking for this solution and while checking with my Wordpress site I found that it had all the static file paths having domain name like "https://domainname.tld/filepath/filename.js" or "https://domainname.tld/filepath/filename.css" similar for media files. So I tried to look for getting the host name and updating staticfile_dir to just mentioning location to static files placed location(in my case I had files in "Project_Dir/App_Dir/templates/App_Dir/Static/"). So that I updated my STATICFILES_DIR = ["Project_Dir/App_Dir/templates/App_Dir/Static/",] and when accessing static file used "" which allowed to me for accessing the static files.

Update

To come over this error I had used a trick which allowed me to access any file from which location I wish under the same folder.

For the solution I had created another application to serve as content delivery network and further to that had create different function which reads the content of the js file and then returns it a for of URL.

By above mean if I had URL named "mydomain.com/foo/file/" and the relavent function to the URL is serve_file which is configured under the URLs file of the Django application.

Then under the views file serve_file function do the thing is it reads the javascript file from its specified location and then it returns the content in a form of javascript like below:

def serve_file(request):
    with open('path/to/javascript/file.js', 'r') as file:
        js_content = file.read()
    return HttpResponse(js_content, content_type='application/javascript')

Upvotes: 0

Glenn
Glenn

Reputation: 5786

You're probably getting that because it's a 404 page because your are not serving the file that you are trying to access. Search for "static" in the PythonAnywhere forums to find out how to configure static files.

Upvotes: 0

Related Questions