خرید بک لینک

Vote count: 0

I am trying to create my own thumbnails within the Django admin and I believe they are being properly pointed to. However I caot view the thumbnail. This is what I see:

enter image description here

When I click on the thumbnail, I get redirected to this URL and all I see is an empty white page.

http://localhost:8000/media/media/Screen_Shot_2016-04-08_at_12.55.25_PM.png

It is the correct URL but I do not see anything within the page.

Here is what code I have:

Within my settings.py

All files will go to chegloong/uploads and /media/ will be the public front facing representation of the MEDIA_ROOT

MEDIA_ROOT = os.path.join(BASE_DIR, 'uploads')
MEDIA_URL = '/media/'

Within chegloong/chegloong/urls.py I appended to the list to serve static files:

urlpattes = [
    url(r'^admin', include(admin.site.urls)),
    url(r'', TemplateView.as_view(template_name="index.html"), name="index"),
    url(r'^api/', include('api.urls'))
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

My chegloong/api/urls.py:

urlpattes = [
    url(r'ig$', most_recent)
]

chegloon/api/models.py:

class Media(models.Model):
    ...
    ...
    file = models.FileField(upload_to="media/", default=None)

chegloong/api/admin.py:

class MediaAdmin(admin.ModelAdmin):
    search_fields = ["name", "file"]
    list_display = ("name", "media_type", "url", "album", "display", "thumbnail")
    def display(self, media_obj):
        retu '<a href="%s">%s</a>' % (media_obj.file.url, media_obj.file.name)

    def thumbnail(self, media_obj):
        location = os.path.join(settings.MEDIA_URL, media_obj.file.name)
        thumbnail_html = "<a href="{0}"><img border="0" alt="" src="{1}" height="80" /></a>".format(location, location)
        retu thumbnail_html

    thumbnail.allow_tags = True
    display.allow_tags = True

Project structure:

enter image description here

asked 53 secs ago

برچسب: نویسنده: استخدام کار تاريخ: شنبه 21 فروردين 1395 ساعت: 6:10

صفحه بندی