# Code example for production(?) - Serving static files during develpoment

**URL:** <https://forum.djangoproject.com/t/code-example-for-production-serving-static-files-during-develpoment/12308>\
**Category:** Deployment\
**Created:** [February 23, 2022, 8:33am UTC](https://forum.djangoproject.com/t/code-example-for-production-serving-static-files-during-develpoment/12308 "2022-02-23T08:33:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sammeeey](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/sammeeey/32/7340_2.png) [@Sammeeey](https://forum.djangoproject.com/u/Sammeeey)\
**Post date:** [February 23, 2022, 8:33am UTC](https://forum.djangoproject.com/t/code-example-for-production-serving-static-files-during-develpoment/12308/1 "2022-02-23T08:33:31Z")

</div>

I am currently on the way to deploy my first Django app.  
Studying the docs I’ve found [_How to manage static files_](https://docs.djangoproject.com/en/4.0/howto/static-files/).  
Within that how-to there is the section [_Serving static files during development_](https://docs.djangoproject.com/en/4.0/howto/static-files/#serving-static-files-during-development).

**I wonder whether the code example within that section is meant for development (as expected from the heading) or rather meant for production (as expected from the description within that section)?**

After describing how it works with the default configuration, they say that the default configurations are not suitable for use in production.  
But then there follows a code example, which looks similar to other resources where people prepare production environments:

```python
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    # ... the rest of your URLconf goes here ...
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

```

I am a bit confused, because static files normally work by default anyway.  
Therefore: Why would that code example describe code for use in the development environment?

---

<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:** [February 23, 2022, 1:10pm UTC](https://forum.djangoproject.com/t/code-example-for-production-serving-static-files-during-develpoment/12308/2 "2022-02-23T13:10:46Z")

</div>

What makes you think the description is meant for production?

There’s a different section for deployment further down, but that’s a different paragraph than the one you’re referencing here.

Also, read the text above that example _carefully_. It explains the situation where that setting is necessary in _a development environment_ and goes on to explain:

> This is not suitable for production use! For some common deployment strategies, see [How to deploy static files](https://docs.djangoproject.com/en/4.0/howto/static-files/deployment/).

One of the key concepts with what I refer to as a “production quality” Django deployment is that Django _never_ serves static files. That functionality is **always** performed elsewhere - apache, nginx, haproxy, AWS S3, CDN, take your pick. But in production, you’re really better off off-loading that process to something other than your Django application.

---

<div class="post-metadata">

**Author:** ![Sammeeey](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/sammeeey/32/7340_2.png) [@Sammeeey](https://forum.djangoproject.com/u/Sammeeey)\
**Post date:** [February 26, 2022, 6:52am UTC](https://forum.djangoproject.com/t/code-example-for-production-serving-static-files-during-develpoment/12308/3 "2022-02-26T06:52:12Z")

</div>

> [@KenWhitesell](#):
>
> What makes you think the description is meant for production?

That’s what makes me wonder:

> [@Sammeeey](#):
>
> I am a bit confused, because static files normally work by default anyway.  
> Therefore: Why would that code example describe code for use in the development environment?

But I rather thought that this part is really meant for development - as you say.

---

<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:** [February 26, 2022, 1:04pm UTC](https://forum.djangoproject.com/t/code-example-for-production-serving-static-files-during-develpoment/12308/4 "2022-02-26T13:04:57Z")

</div>

> [@Sammeeey](#):
>
> I am a bit confused, because static files normally work by default anyway.

They don’t “work by default”. They work because of an installed app - [staticfiles](https://docs.djangoproject.com/en/4.0/ref/contrib/staticfiles/#module-django.contrib.staticfiles).

From the docs you referenced:

> If you don’t have `django.contrib.staticfiles` in [`INSTALLED_APPS`](https://docs.djangoproject.com/en/4.0/ref/settings/#std:setting-INSTALLED_APPS), you can still manually serve static files using the [`django.views.static.serve()`](https://docs.djangoproject.com/en/4.0/ref/views/#django.views.static.serve) view.

That code example goes on to demonstrate how, _in development_, you can serve static files _without_ the staticfiles app installed.

---

<div class="post-metadata">

**Author:** ![Sammeeey](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/sammeeey/32/7340_2.png) [@Sammeeey](https://forum.djangoproject.com/u/Sammeeey)\
**Post date:** [February 27, 2022, 11:46am UTC](https://forum.djangoproject.com/t/code-example-for-production-serving-static-files-during-develpoment/12308/5 "2022-02-27T11:46:00Z")

</div>

Thank you again.  
I didn’t completely realize that this behavior depends on the staticfiles app👍
