On Monday, 6 April 2015 22:38:36 UTC+1, Stephanie Socias wrote:
>
> I've implemented this same solution (using custom file storage and the 
> "upload_to" parameter) but now cannot get the uploaded files to display 
> from my template. I would normally use {{ STATIC_URL }} but, since I've now 
> specified a custom location, I'm not sure why my path, which I've 
> hard-coded in the template, isn't working...any ideas?
>
> fs = FileSystemStorage(location='/data/www/upload')
> def image_location(instance, filename):
>     return '/'.join(['thumbnails', str(instance.dataset_id), filename])
> class DataModel(models.Model):
>     name = models.CharField()
>     date = models.DateField(blank=True)  
>     image = models.ImageField(storage=fs, upload_to=image_location, 
> blank=True)
>
> template.html
>
> <a href="{% url 'myproj:items' %}">
>     <img class="media-object img-thumbnail" src="/data/www/upload/{{ 
> datamine.image }}" alt="Data Image Here" height="130" width="130"></a>
>
>
But /data/www/upload/... is the file path of your upload, not the URL. You 
still need an actual URL that is served by your webserver. Obviously, a 
browser can't access arbitrary file paths on your server.
--
DR. 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e14088d0-7c4a-4965-b88a-2fd0b26ec3cb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to