V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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 · 3633 views
    This topic created in 4840 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
        1
    hfeeki  
       Jan 31, 2013
    请检查你的static目录设置!
    whtsky
        2
    whtsky  
       Jan 31, 2013
    改成/static/img/on.png
    Elwin
        3
    Elwin  
    OP
       Jan 31, 2013
    @hfeeki 目录设置应该是对的,我在一般的视图里加上这条代码

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