Hi Andreas,
I was able to display the images but I dont know how they work. I checked some online resources and found out that I need to add these in my urls.pyfrom django.conf import settings
from django.conf.urls.static import static
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
On Tue, Sep 26, 2017 at 5:23 AM, tango ward <tangoward15@gmail.com> wrote:
I tried applying the object.logo.url but the logo still doesn't display. Also where did the object and url came from?I am having trouble understanding this:Hi Andreas,Really appreciate your guidance on this.
3: All that will be stored in your database is a path to the file (relative toMEDIA_ROOT
). You'll most likely want to use the convenienceurl
attribute provided by Django. For example, if yourImageField
is calledmug_shot
, you can get the absolute path to your image in a template with{{ object.mug_shot.url }}
.On Tue, Sep 26, 2017 at 3:39 AM, Andréas Kühne <andreas.kuhne@hypercode.se> wrote:Hi,--I think you've made a lot of progress!The only thing I think you are missing now is that you should be using the following in your template:<img src="{{ team.logo.url }}">See: https://docs.djangoproject.com/en/1.11/ref/models/ and https://docs.djangoprojectfields/#filefield .com/en/1.11/ref/models/ fields/#django.db.models. fields.files.FieldFile.url Regards,Andréas2017-09-25 20:38 GMT+02:00 tango ward <tangoward15@gmail.com>:To view this discussion on the web visit https://groups.google.com/d/msJarvisThanks,Is there any setting that I missed in media for media?Then I changed my logo to models.ImageField(upload_to='tI added these lines in my settings.pyHi Andréas,Thank you for the response.
MEDIA_DIR = os.path.join(BASE_DIR, 'media')
# Media
MEDIA_ROOT = MEDIA_DIR
MEDIA_URL = '/media/eam_logo'). I also created a 'media' folder inside my project folder which team_logo is a subfolder in it. Tried running the codes again but the logo still wont show.
{% block body_block %}
<p></p>
<div class="row">
{% for team in teams %}
<div class="col-lg-3 col-xs-6 thumbnail">
<img src="{{ team.logo }}">
<p></p>
<label>{{ team.name }}</label>
</div>
{% endfor %}
</div>
{% endblock %}--On Mon, Sep 25, 2017 at 9:10 PM, Andréas Kühne <andreas.kuhne@hypercode.se> wrote:Hi,There are a couple of things to think about here.First of all - just because you put an item on your computer doesn't mean that the icon can be served. For example, if you are running windows and you enter 'C:\pictures\icon.jpg' as the source for the icon, your server won't be able to find it, because the reference 'C:\pictures\icon.jpg' doesn't mean anything for the web browser. The reason the image links you are inputting work is because they probably contain all information, ie http://www.example.com/pictures/icon.jpg .So you can get that sorted and everything should work. HOWEVER, I really think you should use the media storage functionality of Django for this. Checkout : https://docs.djangoproject.com/en/1.11/topics/files/ .If you add the settings required (MEDIA_ROOT in the settings file) and then change you logo from a CharField to an ImageField AND upload your file via django admin, you should be able to show your file.Regards,Andréas2017-09-25 14:38 GMT+02:00 tango ward <tangoward15@gmail.com>:--Any tips please?Problem is, I can't load the images to my html file My logo images are currently stored in my computer. The images will load properly if I grab an image link online and paste the image location to the Logo field in Admin but if I used the absolute path of the images in my computer, the images wont load. When I tried to inspect the page, I am getting "Image could not load".I am writing my pet project which will display a Team name and their logo. I used these lines for my Team class in mode.spy
Hi guys, I am new to django currently stuck in these two.
class Team(models.Model):
name = models.CharField(max_length=150)
logo = models.CharField(null=True, max_length=1000)
def __str__(self):
return self.name
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+unsubscribe@googlegroups.com .
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users .
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAA6wQLJ6kjsd .80%2BcmFOZhPB5C_1Ugnu%3Ds51ais fNgK%3DambvJUg%40mail.gmail.co m
For more options, visit https://groups.google.com/d/optout .
To view this discussion on the web visit https://groups.google.com/d/ms--
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+unsubscribe@googlegroups.com .
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users .gid/django-users/CAK4qSCfrBi-0 .XwcHQLJHWRcfbZHDuXR-ciBx6xB1TR _AR82h%3Dg%40mail.gmail.com
For more options, visit https://groups.google.com/d/optout .
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+unsubscribe@googlegroups.com .
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users .gid/django-users/CAA6wQLLtaj5p .1WPCZ3ozZFMFHyqjg%2B1AoDLzXq8q Y79JNwg%3DwQ%40mail.gmail.com
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+unsubscribe@googlegroups.com .
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users .
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAK4qSCcJ-k%3 .D04nZjF0fY3vqwsbXp4gjMPW6cOZtZ 5n%3DfXrYG6w%40mail.gmail.com
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAA6wQLLsf_VyRizj%2BsXYo7kJSgFD%2BnGrpctnkqic7JU%3DaKO35g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment