推荐学习书目
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 · Nov 23, 2015 · 4737 views
    This topic created in 3903 days ago, the information mentioned may be changed or developed.
    例如:

    文件结构是这样的:
    (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 replies    2015-11-24 09:32:47 +08:00
    chaleaoch
        1
    chaleaoch  
    OP
       Nov 23, 2015
    如果按照 django 的默认配置,他会先找 main ,然后找 apptest 。
    这并不是我想要的。

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

    虽然目前的项目中,还没有这个需求,但是这种情况是必然会出现的。当 app 复用的时候。。。
    geeklian
        2
    geeklian  
       Nov 23, 2015   ❤️ 1
    templates\appname\xxxxx.html
    只能这样咯
    chaleaoch
        3
    chaleaoch  
    OP
       Nov 24, 2015
    @geeklian 昨天睡觉的时候想到了~谢谢大牛~
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2783 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 04:27 · PVG 12:27 · LAX 21:27 · JFK 00:27
    ♥ Do have faith in what you're doing.