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
Elwin
V2EX  ›  Python

关于django admin和static files的问题

  •  
  •   Elwin · 2013-01-31 18:24:29 +08:00 · 2934 次点击
    这是一个创建于 4102 天前的主题,其中的信息可能已经有所发展或是发生改变。
    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 条回复    1970-01-01 08:00:00 +08:00
    hfeeki
        1
    hfeeki  
       2013-01-31 18:32:32 +08:00
    请检查你的static目录设置!
    whtsky
        2
    whtsky  
       2013-01-31 18:35:53 +08:00
    改成/static/img/on.png
    Elwin
        3
    Elwin  
    OP
       2013-01-31 18:45:20 +08:00
    @hfeeki 目录设置应该是对的,我在一般的视图里加上这条代码

    <img class='btn' src='static/img/on.png'>
    都能看到图片,但是admin里就不行。。
    Elwin
        4
    Elwin  
    OP
       2013-01-31 18:45:31 +08:00
    @whtsky 貌似无效。。。
    hfeeki
        5
    hfeeki  
       2013-01-31 18:50:33 +08:00
    admin的静态文件是独立的,请到python的安装目录下的
    lib/python/django/contrib/admin/static
    路径去找admin的static文件
    Elwin
        6
    Elwin  
    OP
       2013-01-31 19:13:12 +08:00
    @hfeeki 恩。。这样啊,那然后应该怎么修改src属性呢?我本来是直接urlpatterns += staticfiles_urlpatterns()的。。现在是不是还要在urls.py里自己配置路由?
    hfeeki
        7
    hfeeki  
       2013-01-31 19:29:51 +08:00
    @Elwin 不用的,admin是作为一个独立的app,他自己处理相关url了。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4075 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 01:00 · PVG 09:00 · LAX 18:00 · JFK 21:00
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.