一、模板
1、模板渲染
$ python manage.py shell
>>>from django.template import template,context
#template定義形式,context定義內容
>>>t=template(...}...)
>>>c=context(......)
>>>print t.render(c)
#render為傳遞引數的方法,模板渲染
2、模板載入
②在settings.py中新增template_dirs=("/var/www/raspberry/templates",),設定路徑
③在工程raspberry中建立templates資料夾,新增模板**time.html檔案 it's now }
④修改views.py檔案
from django.template.loader import get_template
from django.template import context
t=get_template('time.html')
#獲取模板
或者:
from django.shortcuts import render_to_response
...return render_to_response('time.html',)
二、模型
1、資料庫配置
在settings.py檔案中找到databeses=()
#特別注意:'engine': 'django.db.backends.mysql'
databases =}
測試:
$ python manage.py shell
in [1] :from django.db import connection
in [2] :cursor=connection.cursor()
沒提示錯誤就沒問題了
目錄下會出現乙個rasp_test新目錄,ls一下:
admin.py __init__.py migrations models.py tests.py views.py
Django學習筆記第4 5記
一 表單 1 request request包含一些屬性和方法 request.path,get host 等等 request.meta中包含了本次http請求的header資訊,常用的鍵值包括 http referer,http user agent,remote addr 使用如下例 2 表單...
Django學習筆記2
路由 檢視函式 瀏覽器訪問 一級路由 二級路由 常用的屬性 例子from django.db import models db database 資料庫 models 模型 學生表的 用類驅動資料 class user models.model id models.autofield primary...
Django學習筆記2(模板)
這一輪的學習主要是為了掌握django中關於模板的使用,為了開發與維護的高效,必然將要採取模組分離的方法,因此,html檔案最好不要直接硬編碼python,而是html頁面和python 單獨各位一塊,由一些鏈結的橋梁來將html載入到 之中.所以這段時間所學習的模板,其實就是為了達到這個目的,通常...