python - 如何使用 django 正确显示用户生成的图像?

标签 python django settings models imagefield

我正在尝试上传用户生成的图像,然后显示在我的 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/

相关文章:

python - 在 python 中制作图像 flash

python - Google 应用引擎无法实例化超过 Google 应用引擎中 backends.yaml 中定义的后端实例的任务队列

python - 在 Django 中将一个模型与一组另一个模型链接起来

Django 没有在正确的目录中寻找模板

c# - 在 Properties.Settings.Default 与注册表中存储设置

python - Pandas :groupby索引然后使用函数填充数据框

python - 为什么在没有Except block 的情况下Python仍会引发异常?

Python django 无法导入名称 View

visual-studio - 如何在 Visual Studio 2012 中设置 GLM 库

c# - 没有方法和参数描述的 Visual Studio 2013 智能感知