# 生成动态文件链接 # 1.models.py image = models.ImageField(upload_to="文件/%Y/%m", verbose_name="缩略图") # 2.urls.py from django.views.static import serve ... # 配置上传文件的访问处理函数 url(r‘^media/(?P<path>.*)‘, serve, {"document_root":MEDIA_ROOT}) # 3.index.html data-url="{{MEDIA_URL}}{{course_org.image}}" # 4.settings.py MEDIA_URL = "/media/" MEDIA_ROOT = os.path.join(BASE_DIR, ‘media‘)
时间: 2024-10-03 13:10:07