Wednesday, January 9, 2013

Re: show an image in django

My setting.py is:
# Initialize App Engine and import the default settings (DB backend, etc.).
# If you want to use a different backend you have to remove all occurences
# of "djangoappengine" from this file.
from djangoappengine.settings_base import *

import os

# Activate django-dbindexer for the default database
DATABASES['native'] = DATABASES['default']
DATABASES['default'] = {'ENGINE': 'dbindexer', 'TARGET': 'native'}
AUTOLOAD_SITECONF = 'indexes'

SECRET_KEY = '=r-$b*8hglm+858&9t043hlm6-&6-3d3vfc4((7yd0dbrakhvi'

INSTALLED_APPS = (
#    'django.contrib.admin',
    'django.contrib.contenttypes',
    'django.contrib.auth',
    'django.contrib.sessions',
    'django.contrib.staticfiles',
    'djangotoolbox',
    'autoload',
    'dbindexer',
    'shape_practice',

    # djangoappengine should come last, so it can override a few manage.py commands
    'djangoappengine',
   
)

MIDDLEWARE_CLASSES = (
    # This loads the index definitions, so it has to come first
    'autoload.middleware.AutoloadMiddleware',

    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
)

TEMPLATE_CONTEXT_PROCESSORS = (
    'django.contrib.auth.context_processors.auth',
    'django.core.context_processors.request',
    'django.core.context_processors.media',
    'django.core.context_processors.static',
)

# This test runner captures stdout and associates tracebacks with their
# corresponding output. Helps a lot with print-debugging.
TEST_RUNNER = 'djangotoolbox.test.CapturingTestSuiteRunner'

ADMIN_MEDIA_PREFIX = '/media/admin/'
TEMPLATE_DIRS = (os.path.join(os.path.dirname(__file__), 'templates'),)

ROOT_URLCONF = 'urls'
STATIC_URL = '/static/'

# Additional locations of static files
STATICFILES_DIRS = (
    # Put strings here, like "/home/html/static" or "C:/www/django/static".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.   
    "E:/code/python/djangoBook/django-testapp-develop/static",  #this only used for local debug
)

and I use STATIC_URL in the html
<img src="{{ STATIC_URL }}images/gauge_example.jpg" alt = "aa gauge example" width = "390" height = "225" />
But, it must be something wrong in my setting.py since the project can't find the image.
Any suggestions? Thanks.



On Tue, Jan 8, 2013 at 4:00 PM, Mario Gudelj <mario.gudelj@gmail.com> wrote:

Try removing .. from the path. Also make sure your static path is set correctly in settings.py

On 9 Jan, 2013 1:42 AM, "jianhui chen" <jianhui.lab@gmail.com> wrote:
Hi all,
I want to show an image in project in which the folder DIR looks like this:
images/a.jpg
templates/introduction.html

In introduction.html I use
<img src="../images/a.jpg" alt = "example" width = "390" height = "225">

It can show image correctly when I open the "introduction.html" directly using firefox, but it shows ""GET /images/gauge_example.jpg HTTP/1.1" 404 " when I open it in http://127.0.0.1:8000/introduction/, and there is no image in the webpage.

Could anyone give me some suggestions?

jianhui





--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment