我正在尝试上传用户生成的图像,然后显示在我的 django Web 应用程序上。图像正在上传到服务器,但我在显示它时遇到问题。
模型.py
image = models.ImageField(blank=True, null=True, max_length=255, upload_to="images/")
设置.py
MEDIA_ROOT = '/home/user/webapps/static/'
MEDIA_URL = 'http://user.webfactional.com/static/'
举个例子,假设我上传了名为Finland.gif 的文件。我可以看到上传的文件。但是,当我查看源代码时,我看到图像的源代码为“www.foo.com/accounts/profile/images/Finland.gif”,而不是静态图像网址,应为“http://user.webfactional” .com/static/images/Finland.gif”。关于如何解决这个问题有什么建议吗?
最佳答案
userprofile.image.url
为您提供图像的完整 URL
关于python - 如何使用 django 正确显示用户生成的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12577568/