我可以在HTML页面中编写Django查询,然后将其传递给视图以用作Django原始查询吗? 或告诉我如何根据保管箱所选值更新表数据
$(document).on('Change','#sub_select',function(e){
e.preventDefault();
$.ajax({
type:"POST",
url:"{% url 'dashboard_app:group_page' %}",
data:{
sub_team_val:$("#sub_select").val(),
csrfmiddlewaretoken:$('Input[name=csrfmiddlewaretoken]').val()
},
success:function(){
console.log("Values Updates!")
}
})
})
我已经尝试过了,但是没有用,请给我一些好的教程或文档
答案 0 :(得分:0)
这是我的观点@Ivan Starostin
def Group_View(request):
if request.user.is_authenticated:
if request.session.has_key('username'):
name=request.session['username']
data_dict= dict()
if request.method== "POST" and request.is_ajax():
value=request.POST['sub_team_val']
data_dict['data']=list(team.objects.all().values())
data_dict['students']=list(Student.objects.all().values())
return HttpResponse(json.dumps(data_dict))
val=request.GET.get('subject_select_value')
sub_data=Subject.objects.all()
data=team.objects.all()
initial_value=Subject.objects.get(pk="CSD101")
return render(request, "dashboard_app/group.html",{'name':name, 'data':data ,'sub_data':sub_data, 'initial_value':initial_value})
else:
return render(request, "Login_app/index.html")
else:
return render(request,'Login_app/index.html')