Django ModelForm with prefix <p>I have a template with 2 forms. I would like to use "prefix" parameter to have different id in my rendered template like that :</p> <p>My first form :</p> <pre><code>&lt;input id="id_folder-name" maxlength="75" name="folder-name" type="text" /&gt; </code></pre> <p>My second form :</p> <pre><code>&lt;input id="id_file-name" maxlength="75" name="file-name" type="text" /&gt; </code></pre> <p>I my view, I instantiate forms :</p> <pre><code>self.form_class(prefix="folder") self.form_class_upload(prefix="file") </code></pre> <p>but it doesn't work, see console log :</p> <pre><code>[23/Aug/2013 11:15:57] "GET /sample/ HTTP/1.1" 200 1037 invalid &lt;tr&gt;&lt;th&gt;&lt;label for="id_name"&gt;Name:&lt;/label&gt;&lt;/th&gt;&lt;td&gt;&lt;ul class="errorlist"&gt;&lt;li&gt;This field is required.&lt;/li&gt;&lt;/ul&gt;&lt;input id="id_name" maxlength="75" name="name" type="text" /&gt;&lt;/td&gt;&lt;/tr&gt; [23/Aug/2013 11:16:50] "POST /sample/new-folder/ HTTP/1.1" 200 634 </code></pre> <p>So it doesn't call my form_valid method...</p> <p>I don't understand why Django doesn't consider 'prefix' parameter for validation form.</p> <p>models.py:</p> <pre><code>from django.db import models class Inode(models.Model): name = models.CharField(max_length=75) file = models.FileField(upload_to="files", null=True) def __unicode__(self): return self.name </code></pre> <p>forms.py :</p> <pre><code>from django import forms from .models import Inode class FileUploadForm(forms.ModelForm): class Meta: model = Inode fields = ['name', 'file'] class NewFolderForm(forms.ModelForm): class Meta: model = Inode fields = ['name'] </code></pre> <p>views.py :</p> <pre><code>from django.views.generic import TemplateView from django.views.generic.edit import FormView from .forms import FileUploadForm, NewFolderForm from .models import Inode class MainView(TemplateView): template_name = "sample/browser.html" form_class = NewFolderForm form_class_upload = FileUploadForm def get_context_data(self, **kwargs): context = super(MainView, self).get_context_data(**kwargs) context['form_new_folder'] = self.form_class(prefix="folder") context['form_upload'] = self.form_class_upload(prefix="file") context["inodes"] = [i for i in Inode.objects.all()] return context class NewFolderView(FormView): template_name = "sample/browser.html" form_class = NewFolderForm success_url = "/sample" def form_invalid(self, form): invalid = super(NewFolderView, self).form_invalid(form) print "invalid" print form return invalid def form_valid(self, form): isvalid = super(NewFolderView, self).form_valid(form) print "valid" return isvalid </code></pre> <p>template :</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html lang='fr' xml:lang='fr'&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt; &lt;title&gt;sample&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form method="post" action="{% url 'sample-new-folder' %}"&gt; {% csrf_token %} {{form_new_folder}} &lt;input type="submit" value="Valider"/&gt; &lt;/form&gt; &lt;form method="post" action="{% url 'sample-upload' %}"&gt; {% csrf_token %} {{form_upload}} &lt;input type="submit" value="Valider"/&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>rendered template :</p> <pre><code>&lt;html lang='fr' xml:lang='fr'&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt; &lt;title&gt;sample&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form method="post" action="/sample/new-folder/"&gt; &lt;input type='hidden' name='csrfmiddlewaretoken' value='btopdI8WyHgqG2ZSTG81yhmaDa9Rk7Is' /&gt; &lt;tr&gt;&lt;th&gt;&lt;label for="id_folder-name"&gt;Name:&lt;/label&gt;&lt;/th&gt;&lt;td&gt;&lt;input id="id_folder-name" maxlength="75" name="folder-name" type="text" /&gt;&lt;/td&gt;&lt;/tr&gt; &lt;input type="submit" value="Valider"/&gt; &lt;/form&gt; &lt;form method="post" action="/sample/upload/"&gt; &lt;input type='hidden' name='csrfmiddlewaretoken' value='btopdI8WyHgqG2ZSTG81yhmaDa9Rk7Is' /&gt; &lt;tr&gt;&lt;th&gt;&lt;label for="id_file-name"&gt;Name:&lt;/label&gt;&lt;/th&gt;&lt;td&gt;&lt;input id="id_file-name" maxlength="75" name="file-name" type="text" /&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt;&lt;th&gt;&lt;label for="id_file-file"&gt;File:&lt;/label&gt;&lt;/th&gt;&lt;td&gt;&lt;input id="id_file-file" name="file-file" type="file" /&gt;&lt;/td&gt;&lt;/tr&gt; &lt;input type="submit" value="Valider"/&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>