1

Hi guys I'm new to django, now I'm facing problem that the already loaded bootstrap css template gave no effect on the page. I have read several post of this problem in this site, but none of it work. I use python 3.6.4 and django 2.0.

Here is my settings.py:

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

settings.installed_apps :

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rango'
]

my index.html :

<!DOCTYPE html>
{% load staticfiles %}
<html>
<head>
    <title>Rango</title>
    <!-- CSS -->
    <link rel="stylesheet" type="text/css" href="{% static "css/bootstrap.css" %}" />

the command prompt said :

[17/Feb/2018 20:06:14] "GET /static/css/bootstrap.css HTTP/1.1" 200 178152

When I copy paste all the bootastrap css style to the head it work

When I call an image from same static folder, it also can show the picture

<img src="{% static "images/alif.jpg" %}" width="500px" height="800px" alt="foto alif">

My debug set True and i use virtual environment

I also check on chrome developer tools>network>css. It said the css run

My folder structure:

tango
   |
   static
       |
       css
          |
          bootstrap.css

Can anyone help me to solve this?

syny
  • 68
  • 1
  • 4
principiorum
  • 528
  • 7
  • 21
  • Did you check it ? Maybe you can find answer in there https://stackoverflow.com/questions/7574759/django-cant-get-static-css-files-to-load – syny Feb 17 '18 at 13:41
  • @syny yeah already read it. i also try to open the files through url and get it. 4 hours trying to fix this.. – principiorum Feb 17 '18 at 13:51

2 Answers2

1

i've figure out the problem, it was the False mimetype, so i add

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

and the problem is solved

principiorum
  • 528
  • 7
  • 21
0

Replace the static files loader in your index.html

your code:

{% load staticfiles %}

Replace with:

{% load static %}
Dwi Sulfahnur
  • 46
  • 1
  • 4