# static file respond 404Error on tutorial

**URL:** <https://forum.djangoproject.com/t/static-file-respond-404error-on-tutorial/3642>\
**Category:** Using Django\
**Created:** [July 28, 2020, 2:21am UTC](https://forum.djangoproject.com/t/static-file-respond-404error-on-tutorial/3642 "2020-07-28T02:21:23Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mizikanikyuuri](https://avatars.discourse-cdn.com/v4/letter/m/b487fb/32.png) [@mizikanikyuuri](https://forum.djangoproject.com/u/mizikanikyuuri)\
**Post date:** [July 28, 2020, 2:21am UTC](https://forum.djangoproject.com/t/static-file-respond-404error-on-tutorial/3642/1 "2020-07-28T02:21:23Z")

</div>

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](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.

> <https://github.com/mizikanikyuuri/djangoPractice/tree/master/app/djangopractice>
>
> //github.com/mizikanikyuuri/djangoPractice/tree/master/app/djangopractice

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

> [@Css and js as staticfiles](https://forum.djangoproject.com/t/css-and-js-as-staticfiles/3042):
>
> I started learning django by creating a small site some days ago. The problem is that I can`t make the plugin work properly. The plugin is a small bundle of css and js. I put it into static directory and wrote in settings.file STATIC\_URL = '/static/' STATICFILES\_DIRS = [os.path.join(BASE\_DIR, "static"),] Scripts and css work only on the main.html template where I put such lines \<link rel="stylesheet" href="static/btn/css/bvi.min.css" type="text/css"\> \<script src="{% static 'btn/js/js.cookie…

> [@Static file not working](https://forum.djangoproject.com/t/static-file-not-working/853/2):
>
> How are your running your application? Are you talking about in debug / testing mode using runserver, or are you talking about in a production mode? The two answers are different. In a test/debug mode, there are settings file settings that need to be set - see the [static-files how-to page.](https://docs.djangoproject.com/en/3.0/howto/static-files/) In a production environment, you may want the static files served by your webserver (Nginx / Apache). If your settings are correct, you would use the “collectstatic” management command to copy those files …

> [@Css wont load](https://forum.djangoproject.com/t/css-wont-load/2108):
>
> Hi for some reason my CSS file won’t load. I try to search the internet but didn’t found a solution. can you assist me ? my settings.py STATIC\_ROOT= os.path.join(BASE\_DIR,‘staticfiles’) STATIC\_URL = ‘/static/’ MEDIA\_ROOT = os.path.join(BASE\_DIR, ‘media/’) MEDIA\_URL = ‘/media/’ STATICFILES\_DIRS = ( os.path.join(BASE\_DIR, ‘static’), ) my html page: in the start i have : {% load static %} \<script src="{% static 'js/main.js' %}"\>\</script\> \<link rel=”stylesheet” href=" {% static 'c…

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.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [July 28, 2020, 2:53am UTC](https://forum.djangoproject.com/t/static-file-respond-404error-on-tutorial/3642/2 "2020-07-28T02:53:04Z")

</div>

What happens if you point your browser directly at:  
`http://localhost:8080/static/practice1/style.css`?

You _should_ get the actual css file, in which case the problem is probably related to the mimetypes issue.

However, if it returns a 404 in this situation, then it is a static-file related setting.

---

<div class="post-metadata">

**Author:** ![mizikanikyuuri](https://avatars.discourse-cdn.com/v4/letter/m/b487fb/32.png) [@mizikanikyuuri](https://forum.djangoproject.com/u/mizikanikyuuri)\
**Post date:** [July 28, 2020, 5:30am UTC](https://forum.djangoproject.com/t/static-file-respond-404error-on-tutorial/3642/3 "2020-07-28T05:30:05Z")

</div>

Thank you for respose.  
Here is the response of [http://localhost:8080/static/practice1/style.css](http://localhost:8080/static/practice1/style.css)

"Page not found (404)  
Request Method: GET  
Request URL: [http://localhost:8080/static/practice1/style.css](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."

It looks like static-file setting issue.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [July 28, 2020, 12:15pm UTC](https://forum.djangoproject.com/t/static-file-respond-404error-on-tutorial/3642/4 "2020-07-28T12:15:03Z")

</div>

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](https://docs.djangoproject.com/en/3.0/ref/settings/#static-root) (only needed in a production mode) or [STATICFILES\_DIRS](https://docs.djangoproject.com/en/3.0/ref/settings/#staticfiles-dirs).

---

<div class="post-metadata">

**Author:** ![mizikanikyuuri](https://avatars.discourse-cdn.com/v4/letter/m/b487fb/32.png) [@mizikanikyuuri](https://forum.djangoproject.com/u/mizikanikyuuri)\
**Post date:** [July 28, 2020, 1:13pm UTC](https://forum.djangoproject.com/t/static-file-respond-404error-on-tutorial/3642/5 "2020-07-28T13:13:48Z")

</div>

Sorry for the counfution about setting.py.

> 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.

“”"  
LoadModule wsgi\_module modules/mod\_wsgi-py36.cpython-36m-x86\_64-linux-gnu.so  
WSGIScriptAlias / /usr/src/app/djangopractice/djangopractice/wsgi.py  
WSGIPythonPath /usr/src/app/djangopractice/

\<Directory /usr/src/app/djangopractice/djangopractice\>  
  
Require all granted  
  
  
“”"

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”.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [July 28, 2020, 1:29pm UTC](https://forum.djangoproject.com/t/static-file-respond-404error-on-tutorial/3642/6 "2020-07-28T13:29:59Z")

</div>

Ok, so you’re operating in a production-style mode.

You’ll want to start from [https://docs.djangoproject.com/en/3.0/howto/deployment/wsgi/modwsgi/](https://docs.djangoproject.com/en/3.0/howto/deployment/wsgi/modwsgi/) going through this _very_ carefully.

I’ll also recommend [https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/](https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/) and [https://docs.djangoproject.com/en/3.0/howto/static-files/deployment/#deploying-static-files](https://docs.djangoproject.com/en/3.0/howto/static-files/deployment/#deploying-static-files)

But very briefly -

- Yes, collectstatic should be part of your process
- The files should be collected to a location _outside_ your project directory
- You will need to set up an Apache configuration section for ‘/static’

---

<div class="post-metadata">

**Author:** ![mizikanikyuuri](https://avatars.discourse-cdn.com/v4/letter/m/b487fb/32.png) [@mizikanikyuuri](https://forum.djangoproject.com/u/mizikanikyuuri)\
**Post date:** [July 28, 2020, 2:12pm UTC](https://forum.djangoproject.com/t/static-file-respond-404error-on-tutorial/3642/7 "2020-07-28T14:12:53Z")

</div>

Oh, OK.So it means, I misunderstood about differcence between debug and puroduction mode.

Thank you very much. Quick response and goood advice!  
I will try it as production-style. 😀
