Template can't find image file

54 views
Skip to first unread message

Gary Roach

unread,
Dec 7, 2015, 6:46:14 PM12/7/15
to django...@googlegroups.com
While I'm working with "Tango with Django" I am using Django 1.8 and
Python 3.4 (debian linux).

My project tree (somewhat truncated) is in the /root directory and looks
as follows:

tango
├── bin
├── include
├── lib
└── tango
├── db.sqlite3
├── __init__.py
├── manage.py
├── rango
├── requirements.txt
├── static
│ ├── images
│ └── __init__.py
├── tango
│ ├── __init__.py
│ ├── __init__.pyc
│ ├── __pycache__
│ ├── settings.py
│ ├── settings.pyc
│ ├── urls.py
│ └── wsgi.py
├── tango.nja
└── templates
├── __init__.py
└── rango

The pertinent parts of the settings.py file are:

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {

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

STATIC_URL = '/static/'

STATICFILES_DIRS = (
STATIC_PATH,
)

The rango index.html file is:

<!DOCTYPE html>

{% load static from staticfiles %}
<html>

<head>
<title>Rango</title>
</head>

<body>
<h1>Rango says...</h1>
hello world! <strong>{{ boldmessage }}</strong><br />
<a href="/rengo/about">About</a><br />
<img src="{% static "images/apache2.png" %}" alt="Picture of
Apache logo"/>
</body>

</html>

The apache2.png is just a handy image file.

The result of 127.0.0.1:8000/rango/ is:

Rango says...
hello world! I am bold font from the context
About
Picture of Apache logo

I've tried everything I can think of to try to get the image served and
have totally failed. The firefox debugger just says "failed to load the
given URL"

What am I doing wrong.

Gary R



Lucas Magnum

unread,
Dec 8, 2015, 7:00:09 AM12/8/15
to django...@googlegroups.com

[]'s

Lucas Magnum.





--
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/56661A1E.30803%40verizon.net.
For more options, visit https://groups.google.com/d/optout.

Gary Roach

unread,
Dec 8, 2015, 11:52:34 AM12/8/15
to django...@googlegroups.com
OOPs forgot to include these.

/root/tango/tango/urls.py is:

from django.conf.urls import include, url

from django.contrib import admin


urlpatterns = [

url(r'^admin/', include(admin.site.urls)),

url(r'^rango/', include('rango.urls', namespace='rango')),

]


/root/tango/rango/urls.py is:


from django.conf.urls import patterns, url

from rango import views

urlpatterns = patterns('',

url(r'^$', views.index, name='index'),

)


rango/views.py is:

from django.shortcuts import render

def index(request):

context = {'boldmessage': "I am bold font from the context"}

return render(request, 'rango/index.html', context)

--------------------------
I hope this helps


Gary R.


Reply all
Reply to author
Forward
0 new messages