0

I am trying to build a django app and host it on webfaction.

My model looks like this:

class Post(models.Model):
    title = models.CharField(max_length=512)
    image = models.ImageField(upload_to='blogImages/')
    body = models.TextField()
    visible = models.BooleanField()
    date_created = models.DateTimeField(auto_now_add=True)
    date_updated = models.DateTimeField(auto_now=True)
    tags = models.ManyToManyField('Tag', null=True, blank=True)

    def __unicode__(self):
        return self.title

The settings look like this:

MEDIA_ROOT = '/home/myself/webapps/dev_static/media/'
MEDIA_URL = 'http://dev.example.com/static/media/'
STATIC_ROOT = '/home/myself/webapps/dev_static/'
STATIC_URL = 'http://dev.example.com/static/'

When I go to my server and try to upload an image, I get this error:

SuspiciousOperation at /admin/blog/post/add/
Attempted access to '/home/myself/wrong/path/appname/blogImages/Portal2-Logo.jpg' denied.

I'm trying to figure out where the wrong path could come from. Where else should I look for the wrong path?

quakkels
  • 11,676
  • 24
  • 92
  • 149
  • See another question : http://stackoverflow.com/questions/3631941/django-uploading-file-not-in-media-root-path-is-giving-me-suspiciousoperation-er – Cheung Dec 10 '12 at 01:44

2 Answers2

0

i have had the same problem, solved with

 image = models.ImageField(upload_to='/blogImages/') 

instead of (upload_to='blogImages/')

jxs
  • 457
  • 4
  • 9
0

The error is returning the old static media path. It started working correctly using the the correct path after I restarted Apache.

quakkels
  • 11,676
  • 24
  • 92
  • 149