사용자가 버튼을 클릭 할 때 대화 상자를 만들려고하지만 오류가 계속 발생합니다. 이것은 내가 가진 코드입니다.Ajax가있는 장고 클래스 기반 뷰?
참고로 django-braces를 사용하여 ajax 호출을 수신합니다.
보기 :
class UserRegistration(braces.AjaxResponseMixin, CreateView):
form_class = UserRegistrationForm
template_name = "registration_form.html"
def get_ajax(self, request, *args, **kwargs):
context = self.get_context_data(**kwargs)
rendered = render_to_string(self.template_name, context_instance=context)
return HttpResponse(rendered)
자바 스크립트 :
$("#signup").on("click", function(){
$("body").append("<div id='dialog' title='Register'></div>");
$("#dialog").dialog({
height: 'auto',
width: 'auto',
modal: true,
autoOpen: false
});
$.ajax({
url: '/signup/',
data: {},
type: 'GET',
success: function(data){
$("#dialog").html(data);
$("#dialog").dialog("open");
},
error: function(error) {
alert("failure");
}
});
});
나는 그것이 단순히 같은 동일 rendered
을 설정하는 경우 때문에 render_to_string
함께 할 수있는 뭔가 알고이 일 것 "이 일부 텍스트가" ,하지만 내가 뭘 잘못하고 있는지 모르겠다.