its-django / mysite

<<It's Django - 用Python迅速打造Web應用>> 書中程式碼
Apache License 2.0
48 stars 25 forks source link

Template #4

Open myyang opened 9 years ago

myyang commented 9 years ago
======================================
origin (可能會被覆蓋或不清楚的) 
render('input.html') 可能取到project templates下的input.html
======================================
project/
    - templates/
        # global used html
        input.html
        .....
    - manage.py
    - app1/
        - views.py
        - templates/
            - input.html

    - app2/
        - views.py
        - templates/
            - input.html

=======================
路徑加上層資料夾,使其變唯一,則較清晰
render('input.html') 專案層下的templates中的檔案
render("app1/input.hml") 取到app1中的檔案
=======================
project/
    - templates/
        # global used html
        input.html
        .....
    - manage.py
    - app1/
        - views.py
        - templates/
            - app1/
                - input.html

    - app2/
        - views.py
        - templates/
            - app2/
                - input.html

====================
也可寫成下面的方法,也是需加上層路徑
但如此一來app便較無可攜性
====================
project/
    - templates/
        # global used html
        input.html
        - app1/
            - input.html
        - app2/
            - input.html
        .....
    - manage.py
    - app1/
        - views.py
    - app2/
        - views.py