看板 Python 關於我們 聯絡資訊
可以參考 Django 官方教學 https://docs.djangoproject.com/en/1.9/intro/tutorial03/ index.html 要放成這樣: your_app/templates/your_app/index.html 一個解法是: # your_app/views.py from django.template import loader ... def math(request, a, b): ... template = loader.get_template('your_app/index.html') return HttpResponse(template.render({}. request)) 我覺得官方寫得滿好的,建議讀一下 ※ 引述《noimone (算了...)》之銘言: : 大家好 我是最近剛學django的新手 : 買了一本"IT'S django" 在邊看邊學中 : 但是在CP6的範例中 遇到了問題 : 以下是程式碼幾個檔案內容 : https://drive.google.com/open?id=0B5BYZj91rSQHWHFJSmRBZWpJckU : 執行伺服器後的顯示結果 : https://drive.google.com/open?id=0B5BYZj91rSQHdkdUc0dhbEdndDg : views.py 中的前一個範例程式碼 : 這一段這樣寫的時候就沒有問題 : t=template.Template('<html>sun={{s}}<br>dif={{d}}<br>pro={{p}}<br>quo={{q}}</html>') : 會顯示正確結果 : https://drive.google.com/open?id=0B5BYZj91rSQHSlBja1pJRGJSODQ : 推測是 : with open('templates/math.html','r') as reader: : t=template.Template(reader.read()) : 這一段無法正確讀取資料 : 想問問是哪裡的設定出問題了嗎?上網google過後也找不出所以然來了 : 有試著照網路上的一些解答去嘗試 : 像在setting.py 中的這一段程式碼加入'mysite' 也是不行 : INSTALLED_APPS = [ : 'django.contrib.admin', : 'django.contrib.auth', : 'django.contrib.contenttypes', : 'django.contrib.sessions', : 'django.contrib.messages', : 'django.contrib.staticfiles', : 'mysite', : ] : 有想過要跳過這一段先讀後面的部分 但覺得有問題還是要弄清楚 : 所以上python版來問問有沒有解答~~ : 謝謝大家~ -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 122.116.92.72 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1469460433.A.B29.html
noimone: 謝謝! 07/26 08:48
hateehc: 推 11/16 14:46