Created on 2017年5月15日 @author: loutsjavascript
第1課 做業講解及裝飾器使用 28minuteshtml
def check(func):
def rec(request,*args,**kargs):
return func(request,*args,**kargs)
return rec
前端
@check
def index(request,):
print requestjava
第2課 自定義裝飾器擴展使用 18minutespython
第3課 jquery
第4課 BBS功能分析及介紹 37minutes
分析網站的架構
本身寫數據庫Models
參考網站的前端來寫一個頁面
這節完成了頁面頭部的代碼ajax
第5課 BBS功能之點贊 40minutes
按HTML分幾個部分
頁頭,內容,頁尾
內容中按標題,內容,經過迭代數據庫內容顯示出來
參考頁面寫CSS和jQuery
能夠在函數中定義好幾個參數
item是數據的一條記錄
<a href='' onclick='Favor(this,{{item.id}})'>點贊{{item.favor_count}}</a>
<script type='text/javascript'>
//jquery仍是有錯誤,沒法正常使用20170517
function Favor(doc,id){
$.ajax({
//注意Ajax裏不能用冒號,要用逗號
url:'/addfavor/',
data:{id:id},
type:'POST',
sussess:function(arg){
console.log(arg);
var temp = '贊' + arg;
$(doc).text(temp);
}
})
數據庫
2017/05/22
第6課 BBS功能之評論一 53minutesdjango
思路:
點擊 評論,觸發Reply,Reyly去找父標籤的下一個兄弟標籤的第一個標籤,對這個標籤操做---目前這裏實際操做失敗
在這個標籤下,定義輸入框,和歷史記錄(記錄用Ajax到數據庫裏取),對這個標籤初始CSS爲display:None
能夠在這個標籤裏設定兩個CSS,用於區別後臺數據和當前輸入框,找到歷史的CSS,對這個標籤作添加json
前端:
-----------------------------------------------------------------------------------
<div class='part3'>
<a href='' onclick='Favor(this,{{item.id}})'>點贊{{item.favor_count}}</a>
<a href='' id='id1' onclick='Reply()'>評論{{item.reply_count}}</a>
<span>{{item.create_date|date:'Y-m-d H:i:s'}}</span>
</div>
<!-- 下面自定義一個屬性has-input用於JAVA裏的判斷是否有穿入框了 -->
<div has-input=0 class='part4 hide'>
<!--這底下兩個CSS用於下面Java的處理 -->
<div class='replys'></div>
<div class='input'>
<lable>請輸入內容:</lable>
<textarea></textarea>
<input type='button' value='提交'>
</div>
</div>
function Reply(doc,id){
$.ajax(){
url:'/getreply/',
type:'POST',
data:{nid,id},
sussess:function(callback){
//callback是後臺返回的數據
console.log(callback;)
var obj = jQuery.parseJSON(callback);
$.each(obj,function(k,v){
//當前標籤和父親標籤的下一個標籤的第一個標籤
//$(doc).parent().next().first().text('0000')
var temp = '<p>' + v.fields.content + '</p>';
//這裏找到.reply的CSS,先清除當前的內容,否則會出現重複
$(doc).parent().next().find('.replys').empty();
//這裏找到.reply的CSS,再將返回的數據插進去
$(doc).parent().next().find('.replys').append(temp);
});
//這裏點擊時會去掉當前的hide的CSS
$(doc).parent().next().toggleClass('hide');
}
}
//console.log($('#content').attr('has-input'));
//$('#rid').removeClass('part4');
//toggleClass反覆的加減CSS
//$('#content').toggleClass('hide');
var html = $('#id1').parent().next().first()
console.log(html)
//removeClass('hide');
}
後端:
-----------------------------------------------------------------------------------
def getreply(request):
id = request.POST.get('nic')
#這裏可直接用外鍵__字段獲取另外一張表的內容 user__username new__id
reply_list = Reply.objcects.filter(new__id=id).values('id','content','user__username','create_date')
#json 沒法序列化一個時間,可用serializers來操做
#serialize(format, queryset, **options)
reply_list = serializers.serialize('json', reply_list)
return HttpResponse(reply_list)
2017/05/24
第7課 BBS功能之評論二 55minutes
#用於Jason序列化時間格式
class CJsonEncoder(json.JSONEncoder):
def default(self,obj):
if isinstance(obj,datetime.datetime):
return obj.strftime('%Y-%m-%d %H:%M:%S')
elif isinstance(obj,date):
return obj.strftime('%Y-%m-%d')
else:
return json,JSONEncoder.default(self,obj)
def getreply(request):
id = request.POST.get('nic')
#這裏可直接用外鍵__字段獲取另外一張表的內容 user__username new__id
reply_list = Reply.objcects.filter(new__id=id).values('id','content','user__username','create_date')
#json 沒法序列化一個時間,可用serializers來操做
#serialize(format, queryset, **options)
'''
reply_list = serializers.serialize('json', reply_list)
return HttpResponse(reply_list)
'''
#用本身定義的類來處理時間格式
reply_list = list(reply_list)
json.dumps(reply_list,cls=CJsonEncoder)
return HttpResponse(reply_list)
提交評論,實時在頁面上顯示提交的內容(需提交到數據庫中),同時自動更新評論的數量(也要更新數據庫,並將數量返回給前臺)
前端:
-----------------------------------------------------------------------------------
<div class='part3'>
<a href='' onclick='Favor(this,{{item.id}})'>點贊{{item.favor_count}}</a>
<a href='' class='reply' onclick='Reply(this,{{item.id}})'>評論{{item.reply_count}}</a>
<span>{{item.create_date|date:'Y-m-d H:i:s'}}</span>
</div>
<!-- 下面自定義一個屬性has-input用於JAVA裏的判斷是否有穿入框了 -->
<div has-input=0 class='part4 hide'>
<!--這底下兩個CSS用於下面Java的處理 -->
<div class='replys'></div>
<div class='input'>
<lable>請輸入內容:</lable>
<textarea></textarea>
<!-- 這裏添加item.id,是提交的時候要關聯到這個新聞,不能放到其餘的新聞裏去
這裏的this,同樣經過此標籤的上一個標籤,就是提交的內容 -->
<input type='button' value='提交' onclick='Submit(this,{{item.id}})'>
</div>
</div>
{% endfor %}
</div>
<!-- 遮罩層開始 -->
<div id='shade' class='shade hide'></div>
<!-- 遮罩層結束 -->
<!-- 加載層開始 -->
<div id='loading' class='loading hide'></div>
<!-- 加載層結束 -->
function Submit(doc,id){
//上一個標籤
var value = $(doc).prev().val();
//提交後清除輸入框
$(doc).prev().val('');
$('#shade,loading').removeClass('hide');
$.ajax(){
url:'/submitreply/',
type:'POST',
data:{nid:id,data:value},
sussess:function(callback){
//callback是後臺返回的數據
console.log(callback;)
var callback = jQuery.parseJSON(callback);
if (callback.status==1){
//把數據Append到回覆列表中
temp = '<p>' + callback.data.username + ':' + callback.data.content + '---' + callback.data.create_date + '</p>';
$(doc).parent().prev().append(temp)
//底下兩行代碼可讓評論數實時的更新,添加一條時自動計數
//先提交到後臺,正常保存後自動加1,同時將新的內容和數值提交到前臺
count = '評論' + callback.data.reply_count
$(doc).parent().parent().prev().find('.reply').text(count)
}else{
alert('失敗')}
}
$('#shade,loading').addClass('hide');
}
}
後端:
-----------------------------------------------------------------------------------
def submitreply(request):
ret = {'status':0,'data':'','message':''}
try:
id = request.POST.get('nid')
data = request.POST.get('data')
#獲取新聞的對象
newsObj = News.objects.get(id=id)
obj = Reply.objects.create(content=data,
user=Admin.objects.get(id=request.session['current_user_id']),
new=newsObj)
#評論保存後同時要更新聞的評論條目,自動加1
temp = newsObj.reply_count + 1
newsObj.reply_count = temp
newsObj.save()
#將數量放到前端的字典中
ret['data']= {'reply_count':temp,'content':obj.content,
'user__name':obj.user.username,
'create_date':obj.create_date.strftime('%Y-%m-%d %H:%M:%S')}
ret['status'] = 1
except Exception,e:
ret['message'] = e.message
return HttpResponse(json.dumps(ret))
2017/05/31
第7課 BBS功能之Web聊天室 65minutes
思路:
-----------------------------------------------------------------------------------
文本框裏輸入信息,經過提交=====>觸發一個函數=====>經過jQuery獲得內容=====>發送到後臺,
經過Ajax方式=====>後臺根據獲取的內容,加上時間和用戶存到數據庫中,並將相關內容再返回給
前臺(文本的內容能夠不返回)=====>前臺接收到後臺的數據,經過循環的方式,返回到顯示框中
=====>可經過jQuery的層級查找的方式,找到Html標籤,將內容Append到標籤裏
其中:
後臺取數據,第一次時取最後10條,先倒序,獲得最後的ID=====>第二次取的時間,這是另外一個Ajax,
以這個ID爲準,取大於此ID的數據,這樣就可能取到最新的內容
另外聊天窗口每2秒更新一次,將最新的數據取出來,能夠先定義一個變量爲Ture,執行後變爲False
前臺:
-----------------------------------------------------------------------------------
//這是第7課的內容
function Reply(doc,id){
$.ajax(){
url:'/getreply/',
type:'POST',
data:{nid:id},
sussess:function(callback){
//callback是後臺返回的數據
console.log(callback;)
var obj = jQuery.parseJSON(callback);
//放在這裏,不會每次都清空掉,這樣能夠顯示全部記錄
$(doc).parent().next().find('.replys').empty();
$.each(obj,function(k,v){
//當前標籤和父親標籤的下一個標籤的第一個標籤
//$(doc).parent().next().first().text('0000')
temp = '<p>' + v.username + ':' + v.content + '---' + v.create_date + '</p>';
//這裏找到.reply的CSS,先清除當前的內容,否則會出現重複,這樣只會顯示最新的內容,正常要放到循環外面
//$(doc).parent().next().find('.replys').empty();
//這裏找到.reply的CSS,再將返回的數據插進去
$(doc).parent().next().find('.replys').append(temp);
});
//這裏點擊時會去掉當前的hide的CSS
$(doc).parent().next().toggleClass('hide');
}
}
}
function Submit(doc,id){
//上一個標籤
var value = $(doc).prev().val();
//提交後清除輸入框
$(doc).prev().val('');
$('#shade,loading').removeClass('hide');
$.ajax(){
url:'/submitreply/',
type:'POST',
data:{nid:id,data:value},
sussess:function(callback){
//callback是後臺返回的數據
console.log(callback;)
var callback = jQuery.parseJSON(callback);
if (callback.status==1){
//把數據Append到回覆列表中
temp = '<p>' + callback.data.username + ':' + callback.data.content + '---' + callback.data.create_date + '</p>';
$(doc).parent().prev().append(temp)
//底下兩行代碼可讓評論數實時的更新,添加一條時自動計數
//先提交到後臺,正常保存後自動加1,同時將新的內容和數值提交到前臺
count = '評論' + callback.data.reply_count
$(doc).parent().parent().prev().find('.reply').text(count)
}else{
alert('失敗')}
}
$('#shade,loading').addClass('hide');
}
}
function SendMsg(){
/*
簡單的寫法
獲取Message的內容
var value = $('#message').val()
將內容添加到Pool中
$('#chatpool').append(value)
*/
//正常思路:將要發的內容經過Ajax發送到後臺存放到數據庫中
//再從數據庫獲取時間/內容/用戶返回給前臺
var value = $('#message').val()
value = $('#message').val('')
$.ajax({
url:'/subchat/',
data:{data:value},
type:'POST',
success:function(callback){
var callback = jQuery.parseJSON(callback);
if(callback.status == 1){
var now = callback.data.create_date;
var name = callback.data.username;
//這裏定義的ID是爲了後續取數據時,系統會生成兩條一樣的數據,定義了最後的ID後,就更新的下面getchat2中的ID
window.last_id = callback.data.id;
var template ='<div><div>'+name+'---'+now+'</div>'+value+'</div>'
$('#chatpool').append(template) ;
//先用DOM獲取scroll的高度
var height = document.getElementById('chatpool').scrollHeight();
//再將scrollTop設置爲離頂部這麼高,這樣就讓流動條在最下面
$('#chatpool').scrollTop(height);
}else{
alert('請求異常。');
}
}
})
}
setInterval('going()',2000)
window.is_first = true
function going(){
if(window.is_first){
$.ajax({
url:'/getchart/',
type:'POST',
success:function(callback){
console.log(callback);
callback = jQuery.parseJSON(callback);
callback = callback.reverse()
window.last_id = callback[0].id
$.each(callback,function(k,v){
var now = v.create_date;
var name = v.user__username;
var value = v.content
var template ='<div><div>'+name+'---'+now+'</div>'+value+'</div>'
$('#chatpool').append(template)
});
window.is_first = false;
//先用DOM獲取scroll的高度
var height = document.getElementById('chatpool').scrollHeight()
//再將scrollTop設置爲離頂部這麼高,這樣就讓流動條在最下面
$('#chatpool').scrollTop(height)
}
});
}else{
$.ajax({
url:'/getchart2/',
type:'POST',
data:{lastid:window.last_id}
success:function(callback){
console.log(callback);
callback = jQuery.parseJSON(callback);
if(callback.length>0){
window.last_id = callback[callback.length-1].id
$.each(callback,function(k,v){
var now = v.create_date;
var name = v.user__username;
var value = v.content
var template ='<div><div>'+name+'---'+now+'</div>'+value+'</div>'
$('#chatpool').append(template)
});
}
//先用DOM獲取scroll的高度
var height = document.getElementById('chatpool').scrollHeight()
//再將scrollTop設置爲離頂部這麼高,這樣就讓流動條在最下面
$('#chatpool').scrollTop(height)
}
})
</script>
後臺:
-----------------------------------------------------------------------------------
def subchat(request):
ret = {'status':0,'data':'','message':''}
try:
value = request.POST.get('data')
userobj = Admin.objects.get(id=request.session['current_user_id'])
chatobj = Chat.objects.create(content=value,user=userobj)
ret['status'] = 1
ret['data']= {'id':chatobj.id,
'username':userobj.username,
'content':chatobj.content, #這個能夠不用返回,前端本身就能夠獲取
'create_date':chatobj.create_date.strftime('%Y-%m-%d %H:%M:%S')}
except Exception,e:
ret['message'] = e.message
return HttpResponse(json.dumps(ret))
#用於Jason序列化時間格式
class CJsonEncoder(json.JSONEncoder):
def default(self,obj):
if isinstance(obj,datetime.datetime):
return obj.strftime('%Y-%m-%d %H:%M:%S')
elif isinstance(obj,date):
return obj.strftime('%Y-%m-%d')
else:
return json,JSONEncoder.default(self,obj)
#用於前臺點擊評論時顯示當前新聞的評論內容
def getreply(request):
id = request.POST.get('nic')
#這裏可直接用外鍵__字段獲取另外一張表的內容 user__username new__id
reply_list = Reply.objcects.filter(new__id=id).values('id','content','user__username','create_date')
#json 沒法序列化一個時間,可用serializers來操做
#serialize(format, queryset, **options)
'''
reply_list = serializers.serialize('json', reply_list)
return HttpResponse(reply_list)
'''
#用本身定義的類來處理時間格式
reply_list = list(reply_list)
reply_list = json.dumps(reply_list,cls=CJsonEncoder)
return HttpResponse(reply_list)
#用於前臺提供評論內容
def getchart(request):
chatlist = Chat.objects.all().order_by('-id')[0:10].values('id','content','user__username','create_date')
chatlist = list(chatlist)
chatlist = json.dumps(chatlist,cls=CJsonEncoder)
return HttpResponse(chatlist)
def getchart2(request):
lastid = request.POST.get('lastid')
chatlist = Chat.objects.all().filter(id__gt=lastid).values('id','content','user__username','create_date')
chatlist = list(chatlist)
chatlist = json.dumps(chatlist,cls=CJsonEncoder)
return HttpResponse(chatlist)
做業:
-----------------------------------------------------------------------------------
評論樣式更新
加上分頁
裝飾器使用,想評論可能彈跳出框,先登陸,再發評論
本身能夠寫一個博客,將全部的內容放到上面
前臺
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>louts bbs page</title> <style> .left{ float:left; width:60%; height:300px; background-color:#fff; border:solid 1px; } .right{ float:right; width:30%; height:300px; background-color:#fff; border:solid 1px; } .chat-content{ height:250px; overflow: auto; } .input{ height:50px; } .pg-header { height: 44px; background-color: #de8001; } .pg-body { width: auto; overflow: hidden; height: auto!important; min-height: 713px; padding: 6px 28px 60px; background-color: #fff; } .head-content { width: 1016px; margin: 0 auto; line-height: 44px; position: relative; } .header-menu{ float:left; margin-left:21px; } .digg-logo { width: 121px; height: 23px; background: url(/static/images/logo.png) no-repeat 0 0; float: left; margin-top: 11px; } a.tb { color: black; margin-left: -3px; padding: 0 13px 0 16px; display: inline-block; line-height: 44px; } a.tb:hover { color: #red; background-color:white; } a.active { color: #red; background-color:white; } </style> </head> <body> <div class='pg-header'> <div class='head-content'> <a href="/" class="digg-logo"></a> <div class='header-menu'> <a href='/index' class='tb active'>所有</a> <a href='/index' class='tb'>1024區</a> <a href='/index' class='tb'>老男孩</a> <a href='/index' class='tb'>IT民工</a> </div> <div>當前登陸用戶:{{user}} <a href='/logout/'>退出</a></div> <div></div> </div> </div> <div class='pg-body'> <div class='left'></div> <div class='right'> <div id='chatpool' class='chat-content'></div> <div class='input'> <textarea id='content' rows="3" cols="30"></textarea> <input type='button' value='提交' onclick='submit(this)'/> </div> </div> </div> <div class='pg-buttom'></div> <script src='/static/jquery/jquery-1.8.0.js'></script> <script type="text/javascript"> //這個函數是點擊時觸發一個Ajax的提交 function submit(doc){ //獲取id爲content的值 var value = $('#content').val(); //清空id爲content $('#content').val(''); $.ajax({ url:'/sendmsg/', type:'POST', data:{msg:value}, success:function(callback){ //Json反解析 var callback = jQuery.parseJSON(callback); //根據後臺返回的,若是是1,爲正常 if(callback.status==1){ var username = callback.data.username; var date = callback.data.create_date; //定義全局的LastID,用來發送消息時更新最新ID,方便傳遞給下面函數 window.last_id = callback.data.id var temp = '<div>'+username + '---'+date+'</div><div>'+value+'</div><br>' //將獲得的數據放添加到#chatpool裏 $('#chatpool').append(temp); //先用DOM獲取scroll的高度 var height = document.getElementById('chatpool').scrollHeight() //再將scrollTop設置爲離頂部這麼高,這樣就讓流動條在最下面 $('#chatpool').scrollTop(height) }else{ alert(callback.message) }; } }) } //設定一個定時器,每3秒執行一次 setInterval('going()',3000) //設備一個全局變量,判斷第一次執行時爲True,之後則爲False window.first = true //定義一個函數,當其餘用戶第一次登陸時,顯示最後的10條記錄 function going(){ console.log(window.first); if(window.first){ $.ajax({ url:'/getchat/', type:'POST', success:function(callback){ var callback = jQuery.parseJSON(callback); window.last_id = callback[0].id; var callback = callback.reverse(); $.each(callback,function(k,v){ var username = v.user__username; var date = v.create_date; var value = v.content; var temp = '<div>'+username + '---'+date+'</div><div>'+value+'</div><br>' $('#chatpool').append(temp); }); window.first = false; var height = document.getElementById('chatpool').scrollHeight; $('#chatpool').scrollTop(height); } }); //當不是第一次訪問時,根據最後的ID,來獲得此ID後的數據 }else{ console.log(window.last_id); $.ajax({ url:'/getchat2/', type:'POST', data:{lastid:window.last_id}, success:function(callback){ var callback = jQuery.parseJSON(callback); if(callback.length>0){ //從新定義最後ID window.last_id = callback[callback.length-1].id; console.log(window.last_id); console.log(callback); $.each(callback,function(k,v){ var username = v.user__username; var date = v.create_date; var value = v.content; var temp = '<div>'+username + '---'+date+'</div><div>'+value+'</div><br>' $('#chatpool').append(temp); }); var height = document.getElementById('chatpool').scrollHeight; $('#chatpool').scrollTop(height); } } }); } } </script> </body> </html>
後臺
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.shortcuts import render,render_to_response,HttpResponse, redirect
from models import *
import json
from django.core import serializers
from json.encoder import JSONEncoder
# Create your views here.
def index(request):
all_data = News.objects.all()
return render_to_response('index.html',{'data':all_data})
#用於點贊功能,點擊時寫到數據庫中,並將數據返回給前臺
def addfavor(request):
ret = {'status':0,'data':'','message':''}
try:
#這塊有時會出現Sock錯誤error: [Errno 10053]
id = request.POST.get('id')
newsObj = News.objects.get(id=id)
temp = newsObj.favor_count + 1
newsObj.favor_count = temp
newsObj.save()
ret['status'] = 1
ret['data'] = temp
except Exception,e:
print 'error'
ret['message'] = '頁面出錯了'
print ret['message']
return HttpResponse(json.dumps(ret))
'''
#外鍵取數據能夠用外鍵名稱__id來操做,查詢用點
#若是數據中有時間格式,Json沒法序列化
#可以使用Django的專用包來解決 serializers
#serializers.serialize(format, queryset)
#不能經過Reply('#reply_detail來訪問Part4的內容,這樣點擊後會改變全部
#要經過子標籤的父標籤的下一個標籤來找到$(doc).parent().netx()
$(doc).parent().next().first()找到子類第一個標籤,可用Appen添加內容,
或ToggleClass來去掉CSS
Jquery用來迭代數據,obj是一個序列
$.each(obj,function(k,v){
temp = v.fields
})
'''
def login(request):
if request.methos == 'POST':
username = request.POST.get('usernmae')
password = request.POST.get('password')
try:
#currentObj獲得是一個對象
currentObj = Admin.objects.get(username=username,
passsword=password)
except Exception,e:
currentObj = None
if currentObj:
request.session['current_user_id'] = currentObj.id
return redirect('/index')
else:
return redirect('/login')
return render_to_response('login.html')
def submitreply(request):
ret = {'status':0,'data':'','message':''}
try:
id = request.POST.get('nid')
data = request.POST.get('data')
#獲取新聞的對象
newsObj = News.objects.get(id=id)
obj = Reply.objects.create(content=data,
user=Admin.objects.get(id=request.session['current_user_id']),
new=newsObj)
#評論保存後同時要更新聞的評論條目,自動加1
temp = newsObj.reply_count + 1
newsObj.reply_count = temp
newsObj.save()
#將數量放到前端的字典中
ret['data']= {'reply_count':temp,'content':obj.content,
'user__name':obj.user.username,
'create_date':obj.create_date.strftime('%Y-%m-%d %H:%M:%S')}
ret['status'] = 1
except Exception,e:
ret['message'] = e.message
return HttpResponse(json.dumps(ret))
def subchat(request):
ret = {'status':0,'data':'','message':''}
try:
value = request.POST.get('data')
userobj = Admin.objects.get(id=request.session['current_user_id'])
chatobj = Chat.objects.create(content=value,user=userobj)
ret['status'] = 1
ret['data']= {'id':chatobj.id,
'username':userobj.username,
'content':chatobj.content, #這個能夠不用返回,前端本身就能夠獲取
'create_date':chatobj.create_date.strftime('%Y-%m-%d %H:%M:%S')}
except Exception,e:
ret['message'] = e.message
return HttpResponse(json.dumps(ret))
#用於Jason序列化時間格式
class CJsonEncoder(json.JSONEncoder):
def default(self,obj):
if isinstance(obj,datetime.datetime):
return obj.strftime('%Y-%m-%d %H:%M:%S')
elif isinstance(obj,date):
return obj.strftime('%Y-%m-%d')
else:
return json,JSONEncoder.default(self,obj)
#用於前臺點擊評論時顯示當前新聞的評論內容
def getreply(request):
id = request.POST.get('nic')
#這裏可直接用外鍵__字段獲取另外一張表的內容 user__username new__id
reply_list = Reply.objcects.filter(new__id=id).values('id','content','user__username','create_date')
#json 沒法序列化一個時間,可用serializers來操做
#serialize(format, queryset, **options)
'''
reply_list = serializers.serialize('json', reply_list)
return HttpResponse(reply_list)
'''
#用本身定義的類來處理時間格式
reply_list = list(reply_list)
reply_list = json.dumps(reply_list,cls=CJsonEncoder)
return HttpResponse(reply_list)
#用於前臺提供評論內容
def getchat(request):
chatlist = Chat.objects.all().order_by('-id')[0:10].values('id','content','user__username','create_date')
chatlist = list(chatlist)
chatlist = json.dumps(chatlist,cls=CJsonEncoder)
return HttpResponse(chatlist)
def getchat2(request):
lastid = request.POST.get('lastid')
chatlist = Chat.objects.all().filter(id__gt=lastid).values('id','content','user__username','create_date')
chatlist = list(chatlist)
chatlist = json.dumps(chatlist,cls=CJsonEncoder)
return HttpResponse(chatlist)