Django使用筆記

1.視圖返回HTTP內容

#直接返回文字內容
return HttpResponse('Hello Word! You\'re at the polls index')

#使用模版返回內容
template = loader.get_template('polls/index.html')
return HttpResponse(template.render(context,request))

#簡化的使用模版返回內容
return render(request,'polls/index.html',context)

2.urls.py文件配置內容

#?P<question_id>表示將捕獲的值賦一個變量名,可以直接通過變量名引用他,而不用管位置
url(r'^(?P<question_id>[0-9]+)/results/$',views.results,name='results'),

3.使用mysql數據庫時出現的問題

#需要將django/db/backends/mysql/base.py裏的
DateTimeField(6)改爲DateTimeField
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章