0

I'm developing a a web application which runs on a local server provided by django. The first page index.html has many CSS and javascript files. But, none of them is properly rendered on browser. All the css/js files show same MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff) error. The firefox console shows the error briefly -

The resource from “http://localhost:8000/C:/Users/PYTHON/foodie/static/plugins/scrollTo/jquery.scrollTo.min.js” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff).

Harsha Murupudi
  • 579
  • 1
  • 6
  • 19
YadneshD
  • 396
  • 2
  • 12

2 Answers2

1

check your static files settings in settings.py:

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'templates/static'),
]

and add this in master urls.py:

from django.conf.urls.static import static

if settings.DEBUG:
    urlpatterns = urlpatterns + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
    urlpatterns = urlpatterns + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
1ace
  • 5,272
  • 4
  • 23
  • 30
Mahdi Namaki
  • 300
  • 2
  • 7
  • 1
    Thanks a lot for your answer.... Can you please explain why we need to append the urlpatterns of urls.py? This thing needs to be done only when we are running it locally why? – YadneshD Dec 31 '20 at 07:57
  • Because the project is currently on your local server and web servers such as Nginx or Apache are not installed on your local server. – Mahdi Namaki Dec 31 '20 at 08:11
  • Thanks a lot for your explanation. If possible please edit your answer by adding the 'from django.conf.urls.static import static' statement in the beginning for urls.py file. – YadneshD Jan 05 '21 at 16:35
0

make sure that DEBUG is set to True in your settings

John-Silver
  • 35
  • 1
  • 7