V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
Syesir
V2EX  ›  Python

如何让 django 上传图片后显示的 url 变成绝对路径?

  •  
  •   Syesir · 2015-12-22 16:03:35 +08:00 · 3198 次点击
    这是一个创建于 3067 天前的主题,其中的信息可能已经有所发展或是发生改变。
    第一次用 django 写东西,使用的是 xadmin 的模板,在设置文件上传后。
    出于某种复杂的需要,本人想将上传好的文件链接,显示成绝对路径。
    情况如图,求各位 python 的小伙伴多多指点。
    http://c.picphotos.baidu.com/album/h%3D1044%3Bq%3D90/sign=012383115dafa40f23c6cadd9f50383e/2fdda3cc7cd98d10733a3812263fb80e7bec9022.jpg
    3 条回复    2015-12-23 10:28:06 +08:00
    Syesir
        1
    Syesir  
    OP
       2015-12-22 16:05:30 +08:00
    补充,希望显示的是绝对的 url 路径。
    JohnDeng
        2
    JohnDeng  
       2015-12-22 23:13:21 +08:00
    ```
    # example/models.py
    from django.db import models

    class TestImageModel(models.Model):
    image = models.ImageField()


    # example/views.py

    image_obj = TestImageModel.objects.first()
    print image_obj.image.url
    ```

    记得设置 settings.py 中的 `MEDIA_URL`
    Syesir
        3
    Syesir  
    OP
       2015-12-23 10:28:06 +08:00
    @JohnDeng 谢谢!😄
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1446 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 17:32 · PVG 01:32 · LAX 10:32 · JFK 13:32
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.