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

  • Home
  • SEARCH
  • 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 507487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:48:34+00:00 2026-05-13T06:48:34+00:00

I’ve been running into a problem while trying to delete uploaded images. The error

  • 0

I’ve been running into a problem while trying to delete uploaded images.

The error is along these lines:

SuspiciousOperation: Attempted access to '/media/artists/12-stones/154339.jpg' denied.

After reading around it looks like the error is due to the fact that it’s looking for the image in the wrong place (notice first slash, /media/ doesn’t exist on the filesystem)

My MEDIA_ROOT and MEDIA_URL are:

MEDIA_ROOT = '/home/tsoporan/site/media/'
MEDIA_URL = "/media/

My models upload_to parameter is passed this function:

def get_artist_path(instance, filename):
  return os.path.join('artists', slugify(instance.name), filename)

My questions are:

1) How can I fix this problem for future uploads?

2) Is it possible to fix my current images’ paths without having to reupload?

Regards,
Titus

  • 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-13T06:48:34+00:00Added an answer on May 13, 2026 at 6:48 am

    Well, a little grepping around in the code shows that there may be a deeper error message that got homogenized along the way.

    in django/core/files/storage.py, line 210 (this is in 1.1.1) we have:

    def path(self, name):
        try:
            path = safe_join(self.location, name)
        except ValueError:
            raise SuspiciousOperation("Attempted access to '%s' denied." % name)
        return smart_str(os.path.normpath(path))
    

    So the error has to be coming out of safe_join().

    In django/utils/_os.py, we have the following. Note the ValueError it throws on the third to last line:

    ===========================

    def safe_join(base, *paths):
        """
        Joins one or more path components to the base path component intelligently.
        Returns a normalized, absolute version of the final path.
    
        The final path must be located inside of the base path component (otherwise
        a ValueError is raised).
        """
        # We need to use normcase to ensure we don't false-negative on case
        # insensitive operating systems (like Windows).
        base = force_unicode(base)
        paths = [force_unicode(p) for p in paths]
        final_path = normcase(abspathu(join(base, *paths)))
        base_path = normcase(abspathu(base))
        base_path_len = len(base_path)
        # Ensure final_path starts with base_path and that the next character after
        # the final path is os.sep (or nothing, in which case final_path must be
        # equal to base_path).
        if not final_path.startswith(base_path) \
           or final_path[base_path_len:base_path_len+1] not in ('', sep):
            raise ValueError('the joined path is located outside of the base path'
                             ' component')
        return final_path
    

    ==================

    Hmmm, “The joined path is located outside of the base path component”. Now there are a couple of calls to abspathu() in there (which is defined just above this routine and is different for NT than for other OSes). abspathu() converts all non-absolute paths to absolute by tacking on os.cwdu(), the current working directory.

    Question: By any chance do you have a symlink (symbolic link) to your media directory? In other words, it’s not a direct child of the project directory? I don’t know if this is a valid question, it just popped out of my head.

    Question: What are the values of self.location and name that are being passed to safe_join()?

    Wild-ass-guess: is self.location empty?

    Another wild-ass-guess: did MEDIA_ROOT somehow get changed to /media/?

    If you have your own copy of Django installed (it’s not hard to do), trying putting some print statements in these routines and then run it as the development server. The print output will go to the console.

    Update: Hmmm. You said “2) The values for self.location and name are: /home/tsoporan/site/media and /media/albums/anthem-for-the-underdog/30103635.jpg”

    Does the following path make any sense?

    "/home/tsoporan/site/media/media/albums/anthem-for-the-underdog"
    

    Note the …/media/media/… in there.

    Also, what OS is this? Django rev?

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

Sidebar

Ask A Question

Stats

  • Questions 298k
  • Answers 298k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer According to the documentation you can use a special "?"… May 13, 2026 at 7:26 pm
  • Editorial Team
    Editorial Team added an answer Once you know where the actual dictionary is that it's… May 13, 2026 at 7:26 pm
  • Editorial Team
    Editorial Team added an answer You can use the half-edge data structure. Basically your mesh… May 13, 2026 at 7:26 pm

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a French site that I want to parse, but am running into
I have text I am displaying in SIlverlight that is coming from a CMS

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.