Django parameter transfer


Your own understanding can be regarded as a note, which is convenient for searching in the future. Please correct me if there are errors or other things~

render

Without ginseng

return render(reqeust, "index.html");
<html>
 <div>
 	<p>直接显示页面</p>
 </div>
</html>

With ginseng

Call data directly in html

return render(reqeust, "index.html",{
    
    "res":200});
<html>
 <div>
 	<p>显示页面以及数据{
   
   { res}}</p>
 </div>
</html>

Call data in js

return render(reqeust, "index.html",{
    
    "res":json.dumps(200)});
<html>
 <div>
 	<p>显示页面</p>
 </div>
 <script>
 	var res_data = {
     
     {
     
      res|safe }};
 </script>
</html>

JsonResponse

Without ginseng

$.get('/get_all_nodes/', function (res) {
    
    
	data = {
    
    nodes: res.node, links: res.link}
});
return JsonResponse({
    
    'node': nodes,'link':relationships})

With ginseng

$.get('/get_all_nodes/',{
    
    'params1':12,'params2':13}, function (res) {
    
    
	data = {
    
    nodes: res.node, links: res.link}
});
def do(request):
	p1 = request.GET.get('params1')
	p2 = request.GET.get('params2')
	#######################
	return JsonResponse({
    
    'node': nodes,'link':relationships})

Guess you like

Origin blog.csdn.net/weixin_39333120/article/details/111614425