File tree Expand file tree Collapse file tree 2 files changed +21
-5
lines changed Expand file tree Collapse file tree 2 files changed +21
-5
lines changed Original file line number Diff line number Diff line change 22from django .template import RequestContext
33from django .views .decorators .csrf import csrf_exempt
44from comment_react .models import Comments
5+ from django .http import HttpResponse
6+ import json
57
68@csrf_exempt
79def home (request ):
@@ -16,6 +18,7 @@ def home(request):
1618 "post_id" : obj .post_id ,
1719 }
1820 comments .append (commentCurr )
21+ comments .append ({ 'status_code' : 'success' })
1922 return render_to_response ('index.html' , comments )
2023 elif request .method == 'POST' :
2124 data = request .POST .urlencode ()
@@ -36,8 +39,10 @@ def home(request):
3639 "post_id" : obj .post_id ,
3740 }
3841 comments .append (commentCurr )
42+ comments .append ({ 'status_code' : 'success' })
3943 return render_to_response ('index.html' , comments )
4044
45+ @csrf_exempt
4146def getComments (request ):
4247 data = Comments .objects .all ()
4348 comments = []
@@ -48,7 +53,7 @@ def getComments(request):
4853 "post_id" : obj .post_id ,
4954 }
5055 comments .append (commentCurr )
51- print comments
52- return render_to_response ( 'index.html' , comments )
56+ comments . append ({ 'status_code' : 'success' })
57+ return HttpResponse ( json . dumps ( comments ), content_type = "application/json" )
5358
5459
Original file line number Diff line number Diff line change 11{% load staticfiles %}
22< link rel ="stylesheet " type ="text/css " href ="{% static 'css/style.css' %} ">
3-
43< div id ="content "> </ div >
54< script src ="http://code.jquery.com/jquery-1.10.0.min.js "> </ script >
65< script type ="text/jsx ">
76 /** @jsx React.DOM */
87 var CommentBox = React . createClass ( {
98 getInitialState : function ( ) {
9+ // $.ajax({
10+ // url : "getcomments/",
11+ // type : "POST",
12+ // success : function(data) {
13+ // console.log('success - '+ JSON.stringify(data));
14+ // return data;
15+ // },
16+ // error : function(xhr,errmsg,err) {
17+ // console.log('err');
18+ // console.log(xhr.status + ": " + xhr.responseText);
19+ // return {data: []};
20+ // }
21+ // });
1022 return { data : [ ] } ;
1123 } ,
1224 loadCommentsFromServer : function ( ) {
1628 success : function ( data ) {
1729 console . log ( 'in - ' + data ) ;
1830 this . setState ( { data : data } ) ;
19- console . log ( 'data - ' + data ) ;
2031 } . bind ( this ) ,
2132 error : function ( xhr , status , err ) {
2233 console . log ( 'out' ) ;
@@ -110,7 +121,7 @@ <h1>Comments</h1>
110121 }
111122 } ) ;
112123 React . renderComponent (
113- < CommentBox url = "" pollInterval = { 2000 } /> ,
124+ < CommentBox url = "getcomments/ " pollInterval = { 2000 } /> ,
114125 document . getElementById ( 'content' )
115126 ) ;
116127</ script >
You can’t perform that action at this time.
0 commit comments