can't find static file

94 views
Skip to first unread message

Gary Roach

unread,
Sep 30, 2015, 5:02:39 PM9/30/15
to django...@googlegroups.com
Hi all;

Stats:
Debian Linux 8 (jessie)
python = 2.7.9
Django 1.7 (To match tutorial)
sqlite data base
Using virtualenv

I'm working my way through the Tango With Rango tutorial and have hit a
snag. I added the static/images directory and put in a jpg photo for
data. The system can't find the file. I've tried the usual python
manage.py runserver and then used
/127.0.0.1:8000/static/images/P1000153.JPG which produces:

Request Method: GET
Request URL: http://127.0.0.1:8000/static/image/P1000153.JPG

'image/P1000153.JPG' could not be found

I tried the python manage.py findstatic. Same results. Below are my
project tree and my settings.py file. Probably a stupid error but I
can't find it.

├── db.sqlite3
├── __init__.py
├── manage.py
├── rango
│ ├── admin.py
│ ├── admin.pyc
│ ├── __init__.py
│ ├── __init__.pyc
│ ├── migrations
│ │ ├── __init__.py
│ │ └── __init__.pyc
│ ├── models.py
│ ├── models.pyc
│ ├── tests.py
│ ├── urls.py
│ ├── urls.pyc
│ ├── views.py
│ └── views.pyc
├── static
│ ├── images
│ │ ├── __init__.py
│ │ └── P1000153.JPG
│ └── __init__.py
├── templates
│ ├── __init__.py
│ └── rango
│ ├── index.html
│ └── __init__.py
├── twr_project
│ ├── __init__.py
│ ├── __init__.pyc
│ ├── settings.py
│ ├── settings.pyc
│ ├── urls.py
│ ├── urls.pyc
│ ├── wsgi.py
│ └── wsgi.pyc
└── twr_project.nja

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os

BASE_DIR = os.path.dirname(os.path.dirname(__file__))
TEMPLATE_PATH = os.path.join(BASE_DIR, 'templates')

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'u^y3v@)p)9m#z^1z194r$r$g%*(@v)@+@72uu#bu8&b2=!mpv$'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

TEMPLATE_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',
'rango',
)

MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

ROOT_URLCONF = 'twr_project.urls'

WSGI_APPLICATION = 'twr_project.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.7/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}

# Internationalization
# https://docs.djangoproject.com/en/1.7/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'America/Los_Angeles'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.7/howto/static-files/

STATIC_PATH = os.path.join(BASE_DIR, 'static/')

STATIC_URL = '/static/'

SATATICFILES_DIRS = (
STATIC_PATH,
)
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')

TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or
# "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
TEMPLATE_PATH,
)




Thanks in advance

Gary R.

José Javier Castro Matamoros

unread,
Sep 30, 2015, 5:16:21 PM9/30/15
to django...@googlegroups.com
Hi Gary. Did you read the section Serving static files during development. If you don't maybe this happen because you didn't add this code in the project/urls.py.
rom django.conf import settings
from django.conf.urls.static import static

urlpatterns = patterns('',
    # ... the rest of your URLconf goes here ...
) + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
I hope this help you.



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/560C4DCA.20205%40verizon.net.
For more options, visit https://groups.google.com/d/optout.

James Schneider

unread,
Sep 30, 2015, 6:55:31 PM9/30/15
to django...@googlegroups.com

Also, your error indicates that your URL request is using the 'image' directory, not 'images', which doesn't match your directory structure.

-James

Reply all
Reply to author
Forward
0 new messages