> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to django-users...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
>
To me, it looks like the documentation already gave the answer.
Regards,
Xavier.
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>
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>
--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/aHa0WWHGreY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@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.
Thank you very much for responding, Daniel.I'm sorry I don't quite follow- I've never done this before. I should use the URL {{ datamine.image.url }} in the template?
On Tue, Apr 7, 2015 at 5:36 AM, Daniel Roseman <dan...@roseman.org.uk> wrote:
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 a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/aHa0WWHGreY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAG%2B5VyNHO5H1m_dtE3WVrPE4FgSZ%3D%3Dckj-YFZWdoEWVxU4AKgA%40mail.gmail.com.
You are not set
base_url in FileSystemStorage so you are using MEDIA_URL by
default.
The imagefield url property is called like this
def _get_url(self):
self._require_file() # check if It is an object
return self.storage.url(self.name)
url = property(_get_url)
And
self.storage.url
throw exception ifbase_url is not set.
def url(self, name):
if self.base_url is None:
raise ValueError("This file is not accessible via a URL.")
return urljoin(self.base_url, filepath_to_uri(name))
So, I should try to
call
datamine.image.url()
in shell and see what happen
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAOw%3DD6U5DVY58TUdz4HO_5PcCaQAoyhYgF6_YPL287NE8aTDMQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAG%2B5VyNHO5H1m_dtE3WVrPE4FgSZ%3D%3Dckj-YFZWdoEWVxU4AKgA%40mail.gmail.com.