I don't have a clue here. I've set up a form with ImageField to upload user images via frontend and upload is working fine, though I can't find a way to retrieve the pics url and display it in a template. I did run python manage.py collectstatics. Template files and css load fine, but not any uploaded pictures. Any help is very welcome!
models.py
class Profil(models.Model):
def content_file_name(instance, filename):
return '/'.join(['pics', instance.user.username, filename])
user_pic = models.ImageField(upload_to=content_file_name, blank=True, verbose_name='Foto')
template.html
<form class="mezzanine-form" action="" method="post" enctype="multipart/form-data">
<fieldset>
<legend>Edit Profile</legend>
<img src="{{MEDIA_URL}}pics/{{user.username}}/{{WHAT_SHOULD_BE_HERE?}}">
{% fields_for profile_form %}
{% csrf_token %}
<div class="form-actions">
<input class="btn btn-primary btn-lg pull-right" type="submit" value="Save">
</div>
</fieldset>
</form>
settings.py
PROJECT_ROOT = "/path/to/project/"
PROJECT_DIRNAME = PROJECT_ROOT.split(os.sep)[-1]
CACHE_MIDDLEWARE_KEY_PREFIX = PROJECT_DIRNAME
STATIC_URL = "/static/"
STATIC_ROOT = os.path.join(PROJECT_ROOT, STATIC_URL.strip("/"))
STATICFILES_DIRS = [
os.path.join(PROJECT_ROOT, "static"),
"/path/to/project/static/",
]
MEDIA_URL = STATIC_URL + "media/"
MEDIA_ROOT = os.path.join(PROJECT_ROOT, *MEDIA_URL.strip("/").split("/"))
ROOT_URLCONF = "%s.urls" % PROJECT_DIRNAME
TEMPLATE_DIRS = (os.path.join(PROJECT_ROOT, "templates"),)
httpd.conf
Alias /media/ /path/to/project/static/media/
Alias /static/ /path/to/project/static/
<Directory /path/to/project/static/>
Order allow,deny
Allow from all
</Directory>
<Directory /path/to/project/static/media>
Order allow,deny
Allow from all
</Directory>