0

预先感谢您的帮助。

我的网络应用程序的功能之一是让我使用动态表单系统。我不喜欢在我的 Web 项目中使用第三方应用程序。请阅读代码以了解您是否可以提供帮助。

看法

"""This view filters classgroup and supplies the students data to the template."""

def data_cull (request):
    c = {}
    c.update(csrf(request))
    if request.method == 'POST':
        session = request.POST.get('session', '')
        subclass = request.POST.get('subclass', '')
        arm = request.POST.get('arm', '')

        classgroup = ClassGroup.objects.filter(session = session, level = subclass, class_arm = arm)
        students = classgroup.student.all()
        return render_to_response('result/upload_result.html', {'students': students}, c)
    return render_to_response('result/upload_result.html', c)

def upload_result (request) :
    c = {}
    c.update(csrf(request))
    if request.method == 'POST':

        data = request.POST.keys()

模板

<p> Input the exam scores of the students </p>

<form action = "" method = POST>
    {% for student in students %}
    <label>Name</label>
    <input type="text" name="{{student.name}}" placeholder ="{{student.name}}">
    <label>Mathematics</label>
    <input type="text" name="{{student.name}}_{{mathematics}}">
    <label>English</label>
    <input type="text" name="{{student.name}}_{{english}}">
    <label>Chemistry</label>
    <input type="text" name="{{student.name}}_{{chemistry}}">
    {% endfor %}
    <input type = "submit"
</form>

我想遍历这些POST值,并将它们存储在数据库中。有谁知道我该怎么做?

4

0 回答 0