推荐学习书目
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 · Dec 22, 2015 · 3854 views
    This topic created in 3795 days ago, the information mentioned may be changed or developed.
    第一次用 django 写东西,使用的是 xadmin 的模板,在设置文件上传后。
    出于某种复杂的需要,本人想将上传好的文件链接,显示成绝对路径。
    情况如图,求各位 python 的小伙伴多多指点。
    http://c.picphotos.baidu.com/album/h%3D1044%3Bq%3D90/sign=012383115dafa40f23c6cadd9f50383e/2fdda3cc7cd98d10733a3812263fb80e7bec9022.jpg
    3 replies    2015-12-23 10:28:06 +08:00
    Syesir
        1
    Syesir  
    OP
       Dec 22, 2015
    补充,希望显示的是绝对的 url 路径。
    JohnDeng
        2
    JohnDeng  
       Dec 22, 2015
    ```
    # 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
       Dec 23, 2015
    @JohnDeng 谢谢!😄
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   940 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 19:30 · PVG 03:30 · LAX 12:30 · JFK 15:30
    ♥ Do have faith in what you're doing.