Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

django admin image

from django.utils.html import format_html

@admin.register(Model1) 
class Model1Admin(admin.ModelAdmin):

    def image_tag(self, obj):
        return format_html('<img src="{}" />'.format(obj.image.url))

    image_tag.short_description = 'Image'

    list_display = ['image_tag',]
Comment

django show image in admin page

in main URL:

from django.conf import settings
from django.conf.urls.static import static

urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Comment

PREVIOUS NEXT
Code Example
Python :: sort lexo python 
Python :: most common letter in string python 
Python :: Python Create a nonlocal variable 
Python :: embed variables python 
Python :: binary search recursive python 
Python :: {% load humanise %} 
Python :: python use variable inside pandas query 
Python :: python string to list of chars 
Python :: adding two strings together in python 
Python :: stack adt in python 
Python :: Python get first element from list 
Python :: Python basic discord bot 
Python :: how to repeat code in python until a condition is met 
Python :: how to end a while loop python 
Python :: fastest way to take screenshot python 
Python :: pandas describe 
Python :: Python how to search in string 
Python :: python increment filename by 1 
Python :: python save plot 
Python :: load specific columns dataframe 
Python :: anaconda python 3.6 download 
Python :: python gitignore 
Python :: python if not null 
Python :: infinite monkey theorem 
Python :: complete dates pandas 
Python :: gurobi get feasible solution when timelimit reached 
Python :: how to create one list from 2d list python 
Python :: replace() python 
Python :: megre pandas in dictionary 
Python :: convert PIL RGB to opencv BRG 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =