Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6536301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:28:36+00:00 2026-05-25T10:28:36+00:00

sorry my question is very basic ,I want to display an image in template

  • 0

sorry my question is very basic ,I want to display an image in template page,I am working hours for it,The image is not displaying
I create a new project SecondPrjt ,there is only one view function named ‘index’ and one template named test.html , and create a folder named static in side SecondPrjt folder
and create folder images in it and place all needed images there

urls.py:

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'SecondPrjt.views.home', name='home'),
     (r'^$','views.index'),
    .........
)   

urlpatterns += staticfiles_urlpatterns()

views.py

from django.shortcuts import render_to_response 
def index(request):
    return render_to_response('test.html')

test.html:

img src="{{ STATIC_URL }}images/img03.jpg" width="186" height="186"

settings.py

STATIC_ROOT = "C:/wamp/www/SecondPrjt/static" 
STATIC_URL = '/static/'
STATICFILES_DIRS = (
    "C:/wamp/www/SecondPrjt/static",
)
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)

INSTALLED_APPS = (
    'django.contrib.staticfiles',
)

Can any one suggest whats wrong with me.NoteI am using windows and django1.3 and using development server.Thanks in advance

I got the following after I request http://127.0.0.1:8000/ in browse

c:\wamp\www\SecondPrjt>python manage.py runserver
Validating models...

0 errors found
Django version 1.3, using settings 'SecondPrjt.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
[05/Sep/2011 15:18:24] "GET / HTTP/1.1" 200 89
[05/Sep/2011 15:18:24] <b>"GET /images/img03.jpg HTTP/1.1" 404 2028
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T10:28:37+00:00Added an answer on May 25, 2026 at 10:28 am

    In all likelihood, your problem is that you’ve used absolute URLs in both the STATIC_ROOT and STATICFILES_DIRS.

    If you want to include absolute URLs to each static dir (it feels like a hack, but it is fine, as you should only ever use staticfiles_urlpatterns() in development), then you can fix the issue by simply setting STATIC_ROOT = ''.

    Edit: Looks like that wasn’t your only bug. In addition, if you take a look at your debug output, you’ll notice something strange about the 404 — it’s coming from /images/img03.jpg. If you’ll remember, you tried to append {{ STATIC_URL }} to that, so it should have been /static/images/img03.jpg.

    This is because when using render_to_response, you never pass any context (so the template never has access to STATIC_URL — it thinks it’s blank (hence why you didn’t see the /static/ as part of the image URL. Whenever you want to use ANY context, you MUST pass it to the template. In this case, you should use [RequestContext].

    Therefore, you must make sure you have added django.core.context_processors.static to TEMPLATE_CONTEXT_PROCESSORS in settings.py. You should use render_to_response as follows:

    def index(request):
        return render_to_response('test.html', context_instance=RequestContext(request))
    

    The following is an explanation of what context processors are:

    In settings.py, you then would have something like:

     TEMPLATE_CONTEXT_PROCESSORS = (
         'constant_context_processor.constants',
         'django.core.context_processors.static',
         'django.contrib.auth.context_processors.auth',
         'django.core.context_processors.debug',
         'django.core.context_processors.i18n',
         'django.core.context_processors.media',
         'django.core.context_processors.request', )
    

    The important part here is that you have django.core.context_processors.static. In Django, a context processor is a function that returns a context dict. For instance, in my Django projects, I often use the following code snippet:

    constant_context_processor.py:

    import settings
    def constants(request):
        return {
               'CONSTANTS': settings.CONSTANTS,
        }
    

    (You’ll note that above in settings.py, I used constant_context_processor.constants as one of the context processors). This allows me to define constants in settings.py and to use them in my templates, for instance as something like {{ CONSTANTS.favicon_url }}.

    As you can see, the advantage to context processors and using RequestContext is that context you generally need in your templates gets automatically added, so you don’t have to manually populate a dictionary of your context in every view. Django knows there are certain variables you usually want access to in your templates, so they make them accessible via their context processors (so, for instance, django.core.context_processors.request will give you access to a given request, its GET and POST parameters, and all kinds of metadata from a template, which is often useful if, say, you vary the content based on the GET parameters).

    In your case, you didn’t want to use much context, but you did want to use a little bit ({{ STATIC_URL }}), so you needed at least django.core.context_processors.static.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

sorry, I did not find something useful when searching google. Very basic question, mainly
Sorry for the newbie question but still very new to Ruby and Mongo. Not
I could be not more sorry guys - the question was a very wrong
I'm sorry for this very newbish question, I'm not much given into web development.
Sorry if the question isn't correct, I'm very new in Objective-C. I understand why
Sorry, I know this is a very lame question to ask and not of
Sorry for a long question and not a very descriptive title, but my problem
Sorry this is not a very well defined question, I am thinking about an
Sorry for the very basic question. What does the & operator do in this
I might be asking a very basic question and I am sorry for that.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.