推荐学习书目
› 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
Elwin
V2EX  ›  Python

关于django admin和static files的问题

  •  
  •   Elwin · Jan 31, 2013 · 4017 views
    This topic created in 5025 days ago, the information mentioned may be changed or developed.
    django新手
    参考这篇todo_list教程
    http://lightbird.net/dbe/todo_list2.html#interactive-toggle-boxes

    想修改admin的change-list页面,引用一张图
    代码是这样的:
    <img class='btn' src='static/img/on.png'>
    结果发现没法引用,有没有什么解决方法?感激不尽 :)

    目录结构如下:
    todo-list
    todo-app
    ----img
    --------on.png
    --------off.png
    templates
    ----admin
    --------change-list.html
    todo-list
    7 replies  •  1970-01-01 08:00:00 +08:00
    hfeeki
    hfeeki
    Jan 31, 2013
    1
    请检查你的static目录设置!
    whtsky
    whtsky
    Jan 31, 2013
    2
    改成/static/img/on.png
    Elwin
    Elwin
    OP
    Jan 31, 2013
    3
    @hfeeki 目录设置应该是对的,我在一般的视图里加上这条代码

    <img class='btn' src='static/img/on.png'>
    都能看到图片,但是admin里就不行。。
    Elwin
    Elwin
    OP
    Jan 31, 2013
    4
    @whtsky 貌似无效。。。
    hfeeki
    hfeeki
    Jan 31, 2013
    5
    admin的静态文件是独立的,请到python的安装目录下的
    lib/python/django/contrib/admin/static
    路径去找admin的static文件
    Elwin
    Elwin
    OP
    Jan 31, 2013
    6
    @hfeeki 恩。。这样啊,那然后应该怎么修改src属性呢?我本来是直接urlpatterns += staticfiles_urlpatterns()的。。现在是不是还要在urls.py里自己配置路由?
    hfeeki
    hfeeki
    Jan 31, 2013
    7
    @Elwin 不用的,admin是作为一个独立的app,他自己处理相关url了。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   4329 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 03:57 · PVG 11:57 · LAX 19:57 · JFK 22:57
    ♥ Do have faith in what you're doing.