0

I have build a web application using Django Rest Framework and React, I am using IIS for deployment. It works just fine but I have a problem when trying to deploy Django Admin. The style doesn't show. It shows this:

enter image description here enter image description here

I have tried so many methods to add style to DRF project.

  1. I used collectstatic and added it as application to IIS Manager
  2. I activated mimetype in settings.py to accept .css
  3. I tried to link css files in the to contrib/static with the /static url and added that into urls.py.

None of the above methods were able to solve my problem and I have stuck with this bug for days. Could you help me to figure out this problem.

settings.py config

enter image description here enter image description here

1
  • The script and styleSheet elements will reject responses with incorrect MIME types if the server sends the response header "X-Content-Type-Options: nosniff". This is a security feature that helps prevent attacks based on MIME-type confusion. This change impacts the browser's behavior when the server sends the "X-Content-Type-Options: nosniff" header on its responses.
    – Ding Peng
    Nov 18, 2020 at 8:52

1 Answer 1

0

Your STATIC_ROOT seems to be incorrect. In fact, it will be the place where all statics will be collect by the collectstatic command.
So it has to refer to a path on your server.

You have two possibilities :

  • Build a relative path to a folder called "collected_static" or whatever name you want :
    STATIC_ROOT = BASE_URL / 'collected_static'

  • Build an absolute path to a folder in your server like :
    STATIC_ROOT = '/var/www/my_proj/statics

In development mode, you don't need to collect static, because django knows how to collect dynamically.
In production mode, you need to collect static, because it will provide and group all your statics inside the specified path.

After running python manage.py collectstatic, what is the response ? And can you see your expected statics in the expected folder ?

7
  • I tried both methods but it didn't work, I used BASE_URL to the collectstatic folder but still no style is showing. When I execute python manage.py collectstatic it runs normally and creates static folder in the project folder along settings.py file and I can see the static files for the admin and rest_framework
    – Yasmine
    Nov 9, 2020 at 14:52
  • yes i did run it, and I used the absolute path in the STATIC_ROOT
    – Yasmine
    Nov 9, 2020 at 14:58
  • Could you provide your html template ? I assume that you have added the <link> tag with the correct path as {% static 'path_to_collected_static' %} Maybe you are missing static configuration in your IIS conf ? Have a look on this thread
    – Devart
    Nov 9, 2020 at 15:01
  • I use React JS to implement the frontend so I didn't use html templates. Thank you for the link but I still have this issue, I added the static folder as an application in the IIS config manager and supposedly it's the way to configurate IIS
    – Yasmine
    Nov 9, 2020 at 15:15
  • it shows me this error : The resource at "url.dz/static/admin/css/base.css" has been blocked due to incorrect MIME type ("text / html") (X-Content- Type options: nosniff)
    – Yasmine
    Nov 9, 2020 at 15:21

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.