0

I have deployed my web app on Microsoft IIS on my company server. Web.config file is set up and app is running with all permissions. I have created Virtual Directory (to enable serving static files map a static alias to the static directory, C:/inetpub/wwwroot/PyWeb/static/). No matter what I do I can't get my 'blog/main.css'. CSS is not loaded and I get error:

Refused to apply style from 'http://localhost/static/blog/main.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

settings.py

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
DEBUG = True

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

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

base.html

{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
        <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="shortcut icon" href="/media/favicon.ico">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="{% static 'blog/main.css' %}">

Part href="/media/favicon.ico" is working and my icon is loaded. I have tried to remove rel="stylesheet" but it did not help.

Also, I have run collectstatic:

C:\inetpub\wwwroot\PyWeb>python manage.py collectstatic
Starting Scheduler...

You have requested to collect static files at the destination
location as specified in your settings:

    C:\inetpub\wwwroot\PyWeb\static

This will overwrite existing files!
Are you sure you want to do this?

Type 'yes' to continue, or 'no' to cancel: yes

1 static file copied to 'C:\inetpub\wwwroot\PyWeb\static', 128 unmodified.

I have added following to the settings.py but it did not help:

import mimetypes
mimetypes.add_type("text/css", ".css", True)

All static images from my Media folder are loaded with no problems, I'm just having an issue with my css file. CGI and Static Content is enabled in Windows Features.

1 Answer 1

1

You can try to add staticfiles_urlpatterns() in urls.py to your main application module

from .site import admin
from django.urls import path, include
from django.conf.urls import url
from django.contrib.staticfiles.urls import staticfiles_urlpatterns

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include("auth2.urls")),
    url(r'^ckeditor/', include('ckeditor_uploader.urls')),
]

urlpatterns += staticfiles_urlpatterns()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.