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 7798889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:07:50+00:00 2026-06-02T00:07:50+00:00

So far I made it to the part where a user uploads an image

  • 0

So far I made it to the part where a user uploads an image but how can I use those images which are located in my media folder? Here is what I tried :

my view:

#I even tried to import MEDIA_ROOT to use it in my template...
#from settings import MEDIA_ROOT

def home(request):
    latest_images = Image.objects.all().order_by('-pub_date')
    return render_to_response('home.html',
                             #{'latest_images':latest_images, 'media_root':MEDIA_ROOT},
                             {'latest_images':latest_images,},
                             context_instance=RequestContext(request)
                             )

my model:

class Image(models.Model):
    image = models.ImageField(upload_to='imgupload')
    title = models.CharField(max_length=250)
    owner = models.ForeignKey(User)
    pub_date = models.DateTimeField(auto_now=True)

my template:

{% for image in latest_images %}
    <img src="{{ MEDIA_ROOT }}{{ image.image }}" width="100px" height="100px" />
{% endfor %}

and my settings.py MEDIA_ROOT and URL:

MEDIA_ROOT = '/home/tony/Documents/photocomp/photocomp/apps/uploading/media/'
MEDIA_URL = '/media/'

So again here is what I am trying to do: Use those images in my templates!

  • 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-06-02T00:07:52+00:00Added an answer on June 2, 2026 at 12:07 am

    On development machine, you need to tell the devserver to serve uploaded files

    # in urls.py
    from django.conf import settings
    
    if settings.DEBUG:
        urlpatterns += patterns('',
            url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {
                'document_root': settings.MEDIA_ROOT,
            }),
        )
    
    {# in template, use sorl-thumbnail if your want to resize images #}
    {% with image.image as img %}
    <img src="{{ img.url }}" width="{{ img.width }}" height="{{ img.height }}" />
    {% endwith %}
    
    # furthermore, the view code could be simplified as
    from django.shortcuts import render
    def home(request):
        latest_images = Image.objects.order_by('-pub_date')
        return render(request, 'home.html', {'latest_images':latest_images})
    

    On production environment using normal filesystem storage, ensure the webserver has permission to write to MEDIA_ROOT. Also configure the webserver to read /media/filename from correct path.

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

Sidebar

Related Questions

I need to validate my textbox using JavaScript, so far i made this :
Far as best practices are concerned, which is better: public void SomeMethod(string str) {
so far i only know to use Ctrl-Shift-A to do SVN in TextMate. is
As far as I know there is no way to do this, but I
I'm still not sure how it works(but it's not the point:D). As far as
I've searched a bit for this and tried to implement a self-made solution but
We have a Windows application written in C++, part of which we are trying
I have a unique problem to which I can not find a solution. I
As far as i know, there is no direct equivalent in C#. My current
As far as I know, only the convenience methods return created objects with an

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.