Question

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?

Was it helpful?

Solution 2

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

OTHER TIPS

i have had the same problem, solved with

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

instead of (upload_to='blogImages/')

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top