# STATIC\_ROOT returns wrong path

**URL:** https://forum.djangoproject.com/t/static-root-returns-wrong-path/5994
**Category:** Using Django
**Created:** [January 5, 2021, 3:11pm UTC](https://forum.djangoproject.com/t/static-root-returns-wrong-path/5994 "2021-01-05T15:11:57Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![OmidShojaee](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/omidshojaee/32/2216_2.png) [@OmidShojaee](https://forum.djangoproject.com/u/OmidShojaee)
#### Post date: [January 5, 2021, 3:11pm UTC](https://forum.djangoproject.com/t/static-root-returns-wrong-path/5994/1 "2021-01-05T15:11:57Z")

</div>

Hello,

I am not going to understand how “static” settings are working.

Here’s my settings:

```
BASE_DIR = Path( __file__ ).resolve().parent.parent
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')

```

When I go to Python shell, this is the result:

```
>>> from django.conf import settings
>>> print(settings.BASE_DIR)
F:\test.com
>>> print(settings.STATIC_ROOT)
F:/static/
>>>

```

Why???

---

<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: [January 5, 2021, 3:15pm UTC](https://forum.djangoproject.com/t/static-root-returns-wrong-path/5994/2 "2021-01-05T15:15:42Z")

</div>

When you say you go to the Python shell, are you running `python`, or are you running `manage.py shell` (or `shell_plus`)?

---

<div class="post-metadata">

### Author: ![adamchainz](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/adamchainz/32/26_2.png) [@adamchainz](https://forum.djangoproject.com/u/adamchainz)
#### Post date: [January 5, 2021, 3:30pm UTC](https://forum.djangoproject.com/t/static-root-returns-wrong-path/5994/3 "2021-01-05T15:30:49Z")

</div>

Also you’re using Django 3.1’s pathlib-based `BASE_DIR`. It’s clearer then to use the pathlib API to define `STATIC_ROOT`: `STATIC_ROOT = BASE_DIR / 'static'`

See my post on this change: [https://adamj.eu/tech/2020/03/16/use-pathlib-in-your-django-project/](https://adamj.eu/tech/2020/03/16/use-pathlib-in-your-django-project/)

---

<div class="post-metadata">

### Author: ![OmidShojaee](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/omidshojaee/32/2216_2.png) [@OmidShojaee](https://forum.djangoproject.com/u/OmidShojaee)
#### Post date: [January 5, 2021, 4:09pm UTC](https://forum.djangoproject.com/t/static-root-returns-wrong-path/5994/4 "2021-01-05T16:09:12Z")

</div>

`python manage.py shell`

---

<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: [January 5, 2021, 6:02pm UTC](https://forum.djangoproject.com/t/static-root-returns-wrong-path/5994/5 "2021-01-05T18:02:34Z")

</div>

> [@OmidShojaee](#):
>
> ```auto
> >>> print(settings.BASE_DIR)
> F:\test.com
> 
> ```

This is the only part of this that doesn’t make sense to me. I can’t replicate this in my environment and I can’t think of any specific reason why it should be so.

If you’re looking to diagnose this more closely, I’d try something like adding the following to your settings file:  
`MY_FILE = __file__ `

Then, while in the shell, you can walk through those chained steps one by one to see what you’re getting after each call.  
For example:

```auto
>>> settings.MY_FILE
>>> Path(settings.MY_FILE)
>>> Path(settings.MY_FILE).resolve()
>>> Path(settings.MY_FILE).resolve().parent
>>> Path(settings.MY_FILE).resolve().parent.parent

```

---

<div class="post-metadata">

### Author: ![OmidShojaee](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/omidshojaee/32/2216_2.png) [@OmidShojaee](https://forum.djangoproject.com/u/OmidShojaee)
#### Post date: [January 5, 2021, 6:14pm UTC](https://forum.djangoproject.com/t/static-root-returns-wrong-path/5994/6 "2021-01-05T18:14:32Z")

</div>

Base on @adamchainz reply, I changed the settings to this:

```
STATIC_URL = '/static/'
STATIC_ROOT = BASE_DIR / 'static/' 

```

And now in the shell:

```
>>> from django.conf import settings
>>> print (settings.STATIC_ROOT)
F:\test.com\static
>>>

```

It is correct; however, when I put a test image file in `"F:\test.com\static\images\test.jpg"` and add it to the html like this:

```
{% load static %}
<img src="{% static 'images/test.jpg' %}">

```

I get 404 error. Why?

---

<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: [January 5, 2021, 6:23pm UTC](https://forum.djangoproject.com/t/static-root-returns-wrong-path/5994/7 "2021-01-05T18:23:42Z")

</div>

How are you running Django in this environment?

[STATIC\_ROOT](https://docs.djangoproject.com/en/3.1/ref/settings/#static-root) is the destination for the [collectstatic](https://docs.djangoproject.com/en/3.1/ref/contrib/staticfiles/#collectstatic) command - something done for your production environment.

When you’re working in your development environment, you’d put that image in the appropriate directory within your project. Then your development environment can use this file as well as it being available to collectstatic for production.

The [Managing Static Files](https://docs.djangoproject.com/en/3.1/howto/static-files/) docs covers all the intricacies of static file management - admittedly, not a trivial topic.

---

<div class="post-metadata">

### Author: ![OmidShojaee](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/omidshojaee/32/2216_2.png) [@OmidShojaee](https://forum.djangoproject.com/u/OmidShojaee)
#### Post date: [January 5, 2021, 6:35pm UTC](https://forum.djangoproject.com/t/static-root-returns-wrong-path/5994/8 "2021-01-05T18:35:19Z")

</div>

Thanks. It’s a good thing not to have to import os anymore.

---

<div class="post-metadata">

### Author: ![OmidShojaee](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/omidshojaee/32/2216_2.png) [@OmidShojaee](https://forum.djangoproject.com/u/OmidShojaee)
#### Post date: [January 5, 2021, 7:34pm UTC](https://forum.djangoproject.com/t/static-root-returns-wrong-path/5994/9 "2021-01-05T19:34:35Z")

</div>

What I don’t understand is what `{% load static %}` template tag is actually loading. In my settings above, `STATIC_ROOT` is pointing to correct path but it doesn’t work. Why? I don’t understand the mechanism behind it.

---

<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: [January 5, 2021, 7:37pm UTC](https://forum.djangoproject.com/t/static-root-returns-wrong-path/5994/10 "2021-01-05T19:37:47Z")

</div>

See the [load](https://docs.djangoproject.com/en/3.1/ref/templates/builtins/#load) built-in template tag in addition to the previously identified links.

---

<div class="post-metadata">

### Author: ![OmidShojaee](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/omidshojaee/32/2216_2.png) [@OmidShojaee](https://forum.djangoproject.com/u/OmidShojaee)
#### Post date: [January 5, 2021, 8:30pm UTC](https://forum.djangoproject.com/t/static-root-returns-wrong-path/5994/11 "2021-01-05T20:30:48Z")

</div>

I know how to use `load` tag. I don’t know why `STATIC_ROOT` is not working in development. When I look at the source of output HTML file I see that the `<img>` tag in my template is rendered as `"/static/images/test.jpg"` which is absolutely correct, but it doesn’t work. Why? Django just ignores `STATIC_ROOT` in development?

---

<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: [January 5, 2021, 8:38pm UTC](https://forum.djangoproject.com/t/static-root-returns-wrong-path/5994/12 "2021-01-05T20:38:02Z")

</div>

Again, this is all covered in great detail in the docs for [Managing static files](https://docs.djangoproject.com/en/3.1/howto/static-files/), in this case the [Serving static files in development](https://docs.djangoproject.com/en/3.1/howto/static-files/#serving-static-files-during-development) section.

I’m actually not just dodging your questions - there are a _lot_ of factors involved here regarding other settings in addition to `STATIC_ROOT`. This is not a trivial topic, and you should take some time reading the appropriate docs to understand everything that’s going on and the relationships between the various settings.

---

<div class="post-metadata">

### Author: ![wnesbv69](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/wnesbv69/32/2906_2.png) [@wnesbv69](https://forum.djangoproject.com/u/wnesbv69)
#### Post date: [January 9, 2021, 2:06pm UTC](https://forum.djangoproject.com/t/static-root-returns-wrong-path/5994/13 "2021-01-09T14:06:04Z")

</div>

все дело в проектном (urls.py) там вся настройка и (# DEBUG = False  
DEBUG = True)
