Hello everyone. I’m beginner of Django. Now I’m trying to finish tutorial. I got trouble on step6.
Google chrome developer tool’s console says
‘localhost/:1 Refused to apply style from ‘http://localhost:8080/static/practice1/style.css’ because its MIME type (‘text/html’) is not a supported stylesheet MIME type, and strict MIME checking is enabled.’
I’m testing it on my virtualmachine using Vagrant. About detail enviroment please check github repository below.
I’m following django tutorial steps. I changed only 3 things intentionaly.
1.Changed app name from polls to practice1.
2.Changed setting to use postgres server.
3.Changed setting to use apache and wsgimod.
In my understanding way toplace my static files is following steps.
1.Check setting.py parameter ‘DEBUG = True’.
2 Set parameter ‘STATIC_URL’ & ‘STATIC_ROOT’ in setting.py.
3.Place static files on /PROJECT_ROOT/APP_ROOT/static/APP_NAME_FOLDER/STATCI_FILE_SELF (ex./my_first_django/polls/static/polls/style.css)
I know threre is some similer topix here. As following
I tried “python manage.py collectstatic”.(even it looks like used on produciton mode)
I tried adding following code on setting.py.
“import mimetypes
mimetypes.add_type(“text/css”, “.css”, True)”
I tried set “STATICFILES_DIRS” in setting.py like “PROJECT_ROOT/polls/static/polls/style.css”.(I think this is setting for when I want to place file in another place where is not in app directory.)
But couldnt solve this error.
Plese help me solve this error. And let me know whatis wrong with me.
"Page not found (404)
Request Method: GET
Request URL: http://localhost:8080/static/practice1/style.css
Using the URLconf defined in djangopractice.urls, Django tried these URL patterns, in this order:
admin/
practice1/
The current path, static/practice1/style.css, didn’t match any of these.
You’re seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page."
How exactly are you running your environment? Are you doing this with a runserver command? Or are you running this under a real web server such as Apache / mod_wsgi or nginx / uwsgi?
If you’re currently running this is a development mode, then you wouldn’t need to use collectstatic. The runserver command will load static files from within the project when DEBUG = True.
In your settings file in your repo, I didn’t see settings for STATIC_ROOT (only needed in a production mode) or STATICFILES_DIRS.
How exactly are you running your environment? Are you doing this with a runserver command? Or are you running this under a real web server such as Apache / mod_wsgi or nginx / uwsgi?
I’m runnning this envinronment with Apache / mod_wsgi.So I’m typing “systemctl restart httpd” to restart my webapp.
About django runnning mode, I’m using setting.py with “DEBUG = True”.
In your settings file in your repo, I didn’t see settings for STATIC_ROOT (only needed in a production mode) or STATICFILES_DIRS.
I tried it once but it didn’t worked. So I erased it in commiting files.
I thought it does’t needed when running as debug mode. Or do I need it when I run with Apache / mod_wsgi?
By the way, Is that possible this error caused by my httpd.conf?
I’m not familier with wsgi, so now I’m doubting it.
I added following option to my httpd.conf from default.
I’m not very sure about these settings.Should I add all static folders “Require all granted” option?
When I added those it says “does not match any patterns in djangopractice.urls”.