How do I include image files in Django templates?

前端 未结 11 1640
时光说笑
时光说笑 2020-11-27 10:35

I\'m new to Django and I\'m trying to learn it through a simple project I\'m developing called \'dubliners\' and an app called \'book\'. The directory structure is like this

11条回答
  •  难免孤独
    2020-11-27 10:54

    /media directory under project root

    Settings.py

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

    urls.py

        urlpatterns += patterns('django.views.static',(r'^media/(?P.*)','serve',{'document_root':settings.MEDIA_ROOT}), )
    

    template

     
    

提交回复
热议问题