Django forms security, model form vs forms
<p>I'm learning django little by little I realized that I have some way to make a form, modelforms, forms and basic html with 'action= to view'.</p>

<p>If we talk bout security, what is the best option, I asked that because I have create a form to update data un db, do it with modelform it's very easy but I have follow the queryset rules to do it because I did not found a way to update data with a form made by forms, so I have two questions, if there any best way to make what I made in the next code but following forms, instead to do it?.</p>

<pre><code>def update_info(request, pk):
    if request.method == "POST":
        name = request.POST['name_form']
        company = request.POST['company_form']

        detail = Data.objects.get(pk=pk)

    Data.filter(pk=pk).update(name=name, company=company)

    return HttpResponse('Name: %s Company: %s' % (name,company))
</code></pre>

<p>This code works fine but If you guy see there is not a way or maybe I do not know how to clean the form if form is nos post like, something like this.</p>

<p><strong>This method work with form or modelform</strong></p>

<pre><code>else:
        form = my_form()
</code></pre>

<p>Aso the question is, how can I can the form if this is not a form made with model form.</p>

<p>and </p>

<p>Is there a way to use my form made with .fomrs, to update instead to make it in html ?</p>

<p>Because it work but I need to set a new view in the "action" form.
Thank you !</p>

<p>It will be safer to validate input by forms validation instead of making a direct query. That's also one of the main purpose of django form too. 
And here's the reference of <a href="https://docs.djangoproject.com/en/1.10/topics/forms/" rel="nofollow">django forms</a>.</p>

<p>Back to your code and question I guess the following code can help you.</p>

<p>Pick one solution below and put this into your forms.py:</p>

<pre><code>from django import forms

#sol 1
class MyNewForm(forms.Form):
    name = forms.CharField(label='name', max_length=100)
    company = forms.CharField(label='company', max_length=100)

#sol 2
class MyNewForm(forms.ModelForm):
    model = MyModel
    fields = ["name", "company"]
</code></pre>

<p>And then edit your views.py:</p>

<pre><code># path to your forms.py
from .forms import *

def update_info(request, pk):
    if request.method == "POST":
        form = MyNewForm(request.POST)

        detail = Data.objects.get(pk=pk)
        if form.is_valid():
            cleaned_data = form.cleaned_data
            Data.filter(pk=pk).update(name=cleaned_data["name"], company=cleaned_data["company"])

            return HttpResponse('Name: %s Company: %s' % (cleaned_data["name"], cleaned_data["company"]))
        else:
            return HttpResponse('Form Validation Error!')
</code></pre>

python django forms