Django FileFields not uploading (I've gone through the proper steps...)
I want to enable my users to upload photos. Because of local development issues (I'm on windows), I've used FileFields for the time being rather than ImageFields. On my local server, everything was working just fine. I've also uploaded images remotely in the past, so I know the drill.
For some reason, it's now failing to write the files to the specified directory. I pulled the directory as a part of my general git pull. Could that be the issue.
I've done all the following
Model:
class Post_Photo(models.Model):
post=models.ForeignKey(Post,blank=True,null=True)
photo=models.FileField(upload_to="post_photos")
Settings file:
MEDIA_ROOT = '/path..../public_html/media/' (tried with and w/o trailing slash)
I've changed both the /media and /media/post_photos permissions so that they are writable by apache (www-data).
chgrp www-data post_photos
chmod g+w post_photos
I guess I can try to make it permissions 777. Has anybody run into this problem?开发者_如何学Go
Apparently your MEDIA_URL
points to example.com
. Change it to the address of your site.
file settings.py
, look for:
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash if there is a path component (optional in other cases).
# Examples: "http://media.lawrence.com", "http://example.com/media/"
MEDIA_URL = ''
精彩评论