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

一个 django 项目,下面有两个 app,这两个 app 会分别调用两个 html,但这个两个 html 名字相同。应该如何配置?

  •  
  •   chaleaoch · 2015-11-23 20:08:06 +08:00 · 4228 次点击
    这是一个创建于 3077 天前的主题,其中的信息可能已经有所发展或是发生改变。
    例如:

    文件结构是这样的:
    (django_18)chale@chale-pc:~/learning/mayday/mayday$ tree
    .
    (django_18)chale@chale-pc:~/learning/mayday/mayday$ tree
    .
    ├── apptest
    │   ├── admin.py
    │   ├── __init__.py
    │   ├── models.py
    │   ├── templates
    │   ├── tests.py
    │   └── views.py
    ├── db.sqlite3
    ├── main
    │   ├── admin.py
    │   ├── __init__.py
    │   ├── migrations
    │   │   ├── 0001_initial.py
    │   │   └── __init__.py
    │   ├── models.py
    │   ├── templates
    │   ├── tests.py
    │   └── views.py
    ├── manage.py
    └── mayday
    ├── __init__.py
    ├── settings.py
    ├── urls.py
    └── wsgi.py



    log 是这样的:
    Django tried loading these templates, in this order:
    Using loader django.template.loaders.filesystem.Loader:
    Using loader django.template.loaders.app_directories.Loader:
    /home/chale/.virtualenvs/django_18/local/lib/python2.7/site-packages/django/contrib/admin/templates/index.html (File does not exist)
    /home/chale/.virtualenvs/django_18/local/lib/python2.7/site-packages/django/contrib/auth/templates/index.html (File does not exist)
    /home/chale/learning/mayday/mayday/main/templates/index.html (File does not exist)
    /home/chale/learning/mayday/mayday/apptest/templates/index.html (File does not exist)


    本人菜鸟,大神轻喷。
    3 条回复    2015-11-24 09:32:47 +08:00
    chaleaoch
        1
    chaleaoch  
    OP
       2015-11-23 20:12:31 +08:00
    如果按照 django 的默认配置,他会先找 main ,然后找 apptest 。
    这并不是我想要的。

    如果在 settings 里设置,它会先找 settings 里面的配置,这也不是我想要的。

    虽然目前的项目中,还没有这个需求,但是这种情况是必然会出现的。当 app 复用的时候。。。
    geeklian
        2
    geeklian  
       2015-11-23 21:56:13 +08:00   ❤️ 1
    templates\appname\xxxxx.html
    只能这样咯
    chaleaoch
        3
    chaleaoch  
    OP
       2015-11-24 09:32:47 +08:00
    @geeklian 昨天睡觉的时候想到了~谢谢大牛~
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2899 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 07:50 · PVG 15:50 · LAX 00:50 · JFK 03:50
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.