FileField not uploading_to directory (WEIRD SOLUTION)
EDIT: I decided to try uploading the photos to the media directory itself (upload_to=''). It worked. Question still remains, why can't I upload to the next directory in the path? I've done it successfully on my local server and also remotely in the past. WHAT GIVES?
This is a major problem right now and I can't figure out the issue. I want to save images to the directory "post_photos". On my local, windows environment, this works fine. In the past, I've also g开发者_StackOverflowotten it to work just fine on Linux. Right now, for some reason, my Ubuntu environment won't allowed uploaded files.
class Post_Photo(models.Model):
post=models.ForeignKey(Post,blank=True,null=True)
photo=models.FileField(upload_to="post_photos")
def __unicode__(self):
return str(self.post)
settings file
MEDIA_ROOT = '/path_to_mysite/public_html/media' ##i've also tried this with a trailing slash
On the command line, I've created the directory post_photos in media. As per a tutorial, I chgrp to www-data (i think that's what apache is running as) and, then, chmod g+w. I also tried to just chmod 777 for the directory.
In my admin, the post_photos are saving and it's showing me a path to the images...they just don't actually exist.
Has anyone come across this sort of problem? Should I change the permissions of more directories?
When I try to upload a file in my admin backend, it gives me the following error:
Failed to load source for: http://(mysite.com)/admin/website/post_photo/4/
I think you need to end your MEDIA_ROOT
with a /
MEDIA_ROOT = '/path_to_mysite/public_html/media/'
EDIT
In addition, you need to specify the name of the file in upload_to. You can check out the docs here.
精彩评论