title: Getting an exception raised by django.contrib.staticfiles.views.serve
body: <p>I am naive in Django. Trying out a few pieces of stuff here. I was working with static files and have got stuck here. Please help me out here.</p>
  
  <p>I am very much confused about static_root and static_dirs. I am following an online tutorial where the static root has not been used and their project is working fine. If am trying that I facing lots of errors and exceptions.</p>
  
  <p>Here is my view:</p>
  
  <pre><code>from django.shortcuts import render
  from django.http import HttpResponse
  
  
  
  def index(request):
      my_dict={'insert_me':"Hello I am from views.py"}
      return render(request,'first_app/index.html',context=my_dict)
  </code></pre>
  
  <p>Here is my projects urls:</p>
  
  <pre><code>from django.contrib import admin
  from django.conf.urls import url
  from django.conf.urls import include
  from first_app import views
  from django.contrib.staticfiles.urls import staticfiles_urlpatterns
  
  
  urlpatterns = [
      url(r'^$', views.index, name='index'),
      url(r'^first_app/',include('first_app.urls')),
      url(r'^admin/', admin.site.urls),]
  
  urlpatterns += staticfiles_urlpatterns()
  </code></pre>
  
  <p>Here is my apps url:</p>
  
  <pre><code>from django.conf.urls import url
  from first_app import views
  from django.contrib import admin
  
  urlpatterns= [
      url(r'', views.index, name='index'),]
  </code></pre>
  
  <p>the index.html:</p>
  
  <pre><code>{% load staticfiles%} 
  &lt;html&gt; 
      &lt;head&gt; 
          &lt;meta charset="utf-8"&gt; 
          &lt;title&gt;DJ Page&lt;/title&gt; 
      &lt;/head&gt; 
      &lt;body&gt; 
          &lt;h1&gt;Hello this is index.html!&lt;/h1&gt; 
          &lt;img src="{% static 'images/dj.jpg'%}" alt='oh oh! did not show'&gt; 
      &lt;/body&gt; 
  &lt;/html&gt;
  </code></pre>
  
  <p>and here is my setting:</p>
  
  <p>"""</p>
  
  <pre><code>Django settings for Twenty3rdMrach project.
  
  Generated by 'django-admin startproject' using Django 2.1.2.
  
  For more information on this file, see
  https://docs.djangoproject.com/en/2.1/topics/settings/
  
  For the full list of settings and their values, see
  https://docs.djangoproject.com/en/2.1/ref/settings/
  """
  
  import os
  
  # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
  BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  TEMPLATES_DIR=os.path.join(BASE_DIR,'templates')
  #TEMPLATES_DIR=os.path.join(TEMPLATES_DIR,'first_app')
  print(TEMPLATES_DIR)
  STATIC_DIR=os.path.join(BASE_DIR,'static')
  print (STATIC_DIR   )
  
  
  
  # Quick-start development settings - unsuitable for production
  # See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/
  
  # SECURITY WARNING: keep the secret key used in production secret!
  SECRET_KEY = 'mz^^exko@!2czk35u$w-qr&amp;v8u(46(fp7#u41ctabvwf=mz9m&amp;'
  
  # SECURITY WARNING: don't run with debug turned on in production!
  DEBUG = True
  
  ALLOWED_HOSTS = []
  
  
  # Application definition
  
  INSTALLED_APPS = [
      'django.contrib.admin',
      'django.contrib.auth',
      'django.contrib.contenttypes',
      'django.contrib.sessions',
      'django.contrib.messages',
      'django.contrib.staticfiles',
      'first_app',
  ]
  
  MIDDLEWARE = [
      'django.middleware.security.SecurityMiddleware',
      'django.contrib.sessions.middleware.SessionMiddleware',
      'django.middleware.common.CommonMiddleware',
      'django.middleware.csrf.CsrfViewMiddleware',
      'django.contrib.auth.middleware.AuthenticationMiddleware',
      'django.contrib.messages.middleware.MessageMiddleware',
      'django.middleware.clickjacking.XFrameOptionsMiddleware',
  ]
  
  ROOT_URLCONF = 'Twenty3rdMrach.urls'
  
  TEMPLATES = [
      {
          'BACKEND': 'django.template.backends.django.DjangoTemplates',
          'DIRS': [TEMPLATES_DIR,],
          'APP_DIRS': True,
          'OPTIONS': {
              'context_processors': [
                  'django.template.context_processors.debug',
                  'django.template.context_processors.request',
                  'django.contrib.auth.context_processors.auth',
                  'django.contrib.messages.context_processors.messages',
              ],
          },
      },
  ]
  
  WSGI_APPLICATION = 'Twenty3rdMrach.wsgi.application'
  
  
  # Database
  # https://docs.djangoproject.com/en/2.1/ref/settings/#databases
  
  DATABASES = {
      'default': {
          'ENGINE': 'django.db.backends.mysql',
          'NAME': 'udemy1',
          'USER':'root',
          'PASSWORD':'Ravi@go123',
          'HOST':'localhost',
          'PORT':'3306',
      }
  }
  
  
  # Password validation
  # https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators
  
  AUTH_PASSWORD_VALIDATORS = [
      {
          'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
      },
      {
          'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
      },
      {
          'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
      },
      {
          'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
      },
  ]
  
  
  # Internationalization
  # https://docs.djangoproject.com/en/2.1/topics/i18n/
  
  LANGUAGE_CODE = 'en-us'
  
  TIME_ZONE = 'UTC'
  
  USE_I18N = True
  
  USE_L10N = True
  
  USE_TZ = True
  
  
  # Static files (CSS, JavaScript, Images)
  # https://docs.djangoproject.com/en/2.1/howto/static-files/
  
  STATIC_URL = '/static/'
  STATICFILES_DIR = (os.path.join(BASE_DIR, 'static/'),)
  STATIC_ROOT=os.path.join(BASE_DIR,'static_media/')
  </code></pre>
  
  <p>While hitting the url:</p>
  
  <pre><code>http://127.0.0.1:8000/static/images/dj.jpg
  </code></pre>
  
  <p>am facing the below error:</p>
  
  <pre><code>Page not found (404)
  Request Method: GET
  Request URL:    http://127.0.0.1:8000/static/images/dj.jpg
  Raised by:  django.contrib.staticfiles.views.serve
  'images\dj.jpg' could not be found
  </code></pre>
  
  <p>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.</p>