extjsタブの中で私の最初のdjangoフォームを正常にレンダリングすることができました。フォームデータが正しく表示され、フォームの検証が正しく機能しているように見えます。EXTJSタブの中にDjangoを描画する
私の問題は、djangoが結果を同じタブに戻すだけでなく、新しいページ全体をレンダリングしたいということです。私は完全なページのレンダリングをせずに、このすべてを1つのタブの中に保つことができれば、私のアプリが機能しやすくなると思います。
背景: EXTJS ajaxタブの例を使用してこの作業を行いました。それでは、問題は、例では複数のget/post呼び出しが同じタブにレンダリングされることがなかったため、どうやってそれを行うかわかりません。
質問: POSTデータの結果をEXTJSタブに保存するにはどうすればよいですか?また、これらのアプリをたくさん開発している専門家から、ここで正しいパターンを使用していますか?編集フォームをつかむためにはDjangoの呼び出しを行いEXTJSグリッドを構築し、ユーザーがクリック「編集」アイコン - grid.jsは:
ファイル:
は、ここに私の基本的なレイアウトです。
var createColModel = function (finish, start) {
var columns = [{
dataIndex: 'pk',
header: 'Student ID',
filterable: true
//,filter: {type: 'numeric'}
}, {
// ... More column data here
},{
header: 'Actions',
id: 'actions',
xtype: 'actioncolumn',
width: 50,
items: [{
icon : '/site_media/icons/application_edit.png',
tooltip: 'Edit Record',
handler: function(grid, rowIndex, colIndex) {
var rec = studentStore.getAt(rowIndex);
mainTabPnl.add({
title: rec.get('fields.first_name') + ', ' + rec.get('fields.last_name'),
iconCls: 'tabs',
autoLoad: {url: '/app/edit_student/' + rec.get('pk')},
closable:true
}).show();
}
}]
}];
ファイル:views.py
def edit_student_view(request, sid):
print "Edit Student: " + sid
student = Student.objects.get(pk=sid)
if request.method == 'POST':
form = StudentProfileForm(request.POST, instance=student)
if form.is_valid():
student=form.save()
message="Edit successful"
c = {'form' : form, 'student':student, 'message':message}
return render_to_response('app/edit_student.html', c, context_instance=RequestContext(request))
else:
message = "The form contains errors."
c = {'form':form, 'student':student, 'message':message}
// Problem: This is now rendered as the whole page, not inside the tab
return render_to_response('app/edit_student.html', c, context_instance=RequestContext(request))
else:
form = StudentProfileForm(instance=student)
c = {'form':form, 'student':student}
//Initial GET: renders in correct EXTJS window.
return render_to_response('app/edit_student.html', c, context_instance=RequestContext(request))
ファイル:edit_student.html - あなたは、タブの中でそれを維持したい場合はDjangoのフォーム
{% block mainpanel %}
{% if form.errors %}
<p>The Registration form had errors. Please try again.</p>
{% endif %}
{% if form %}
<form action="/app/edit_student/{{student.student_id}}/" method="post">
<table>
{{ form.as_table }}
</table>
<input type="submit" value="Submit" />
</form>
{%endif%}
{% endblock %}
onClickはまだdjangoフォームをレンダリングできますか?あなたはこの行動の例を知っていますか? – codingJoe
フォームを表示しません。ビューからHTMLフラグメントを返し、配置します。 –