Django Гибкая форма, как я могу защитить ее?

Я знаю, что я делаю форму в foms.py, помещаю ее в контекст и отправляю в HTML. Но я хочу сделать так, чтобы пользователь мог увеличивать и уменьшать форму. Если я буду работать с кодом, который я загрузил сейчас, я знаю, что он очень уязвим для безопасности, поэтому мне интересно, как я могу его защитить. enter image description here

def debate_create(request):

    if request.method == "POST":
        # validation ckeck

        # section dictionary for saving request.FILES
        section_id = dict()
        # save request.POST content
        content = request.POST.items() 
        for k,v in content:
            if k == 'sup_title':
                sup_title = SuperTitle()
                sup_title.author = request.user
                sup_title.super_title = v
                sup_title.save()
                sup_title_id = sup_title.id
            elif 'img' not in k and 'opt' not in k and 'section' in k:
                sub_title = Subtitle()
                sub_title.super_title = get_object_or_404(SuperTitle, pk = sup_title_id)
                sub_title.sub_title = v
                sub_title.save()
                # saving subtitle.id to dictionary
                section_id[f'img_{k}'] = sub_title.id
            elif 'section' in k and 'opt' in k:
                opt = SelectOption()
                opt.sub_title = get_object_or_404(Subtitle, pk = sub_title.id)
                opt.option = v
                opt.save()

        # save request.FILES content
        for key,item in request.FILES.items():
            for image in request.FILES.getlist(key):
                img = Images()
                img.images = image
                img.sub_title = get_object_or_404(Subtitle, pk = section_id[key])
                img.save()
        return render(request, 'polls/test.html')
    else:
        # change HTML index.html to debate_form.html after make it
        return render(request, 'polls/index.html')
Вернуться на верх