Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何使用django正确显示用户生成的图像?_Python_Django_Settings_Models_Imagefield - Fatal编程技术网

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

Python 如何使用django正确显示用户生成的图像?,python,django,settings,models,imagefield,Python,Django,Settings,Models,Imagefield,我正试图上传一张用户生成的图片,然后显示在我的django web应用程序中。图像正在上载到服务器,但我无法显示它 models.py 设置.py 例如,假设我上传了一个名为Finland.gif的文件。我可以看到上传的文件。但是,当我查看源代码时,我看到图像的源代码是“www.foo.com/accounts/profile/images/Finland.gif”,而不是静态图像url,它应该是”http://user.webfactional.com/static/images/Finlan

我正试图上传一张用户生成的图片,然后显示在我的django web应用程序中。图像正在上载到服务器,但我无法显示它

models.py 设置.py
例如,假设我上传了一个名为Finland.gif的文件。我可以看到上传的文件。但是,当我查看源代码时,我看到图像的源代码是“www.foo.com/accounts/profile/images/Finland.gif”,而不是静态图像url,它应该是”http://user.webfactional.com/static/images/Finland.gif". 有没有关于如何解决这个问题的建议?

刚刚解决了。。。我需要包括:

http://user.webfactional.com/static/{{userprofile.image}

userprofile.image.url
提供图像的完整url

您可以显示用于显示图像的代码吗?@Rakesh
image = models.ImageField(blank=True, null=True, max_length=255, upload_to="images/")
MEDIA_ROOT = '/home/user/webapps/static/'
MEDIA_URL = 'http://user.webfactional.com/static/'