Note that there are some explanatory texts on larger screens.

plurals
  1. POform.is_valid() always returning false
    primarykey
    data
    text
    <p>Form.is_valid() is always returning false, and it never shows any kind of error. Following is the code snippet from forms.py, views.py and template/transaction_add_page.html</p> <p><strong>Form</strong></p> <pre><code>class TransactionForm(forms.Form): account = forms.ModelChoiceField(queryset=Account.objects.none()) transactions = forms.CharField(widget=forms.Textarea(attrs={'rows':'10', 'cols':'70'})) def __init__(self, user, *args, **kwargs): super(TransactionForm, self).__init__(*args, **kwargs) self.fields['account'].queryset = Account.objects.filter(user=user) def clean_account(self): if 'account' in self.cleaned_data: account = self.cleaned_data['account'] return account raise forms.ValidationError('Please select an account.') def clean_transactions(self): if 'transactions' in self.cleaned_data: transactions = self.cleaned_data['transactions'] return transactions raise forms.ValidationError('At-least one transaction is required.') </code></pre> <p><strong>View</strong></p> <pre><code>@login_required def transaction_add_page(request): if request.method == 'POST': form = TransactionForm(request.POST) if form.is_valid(): variables = RequestContext(request, {'account': form.clean_account(), 'transactions': form.clean_transactions()}) return render_to_response('transaction_confirm_page.html', variables) form = TransactionForm(request.user) variables = RequestContext(request, {'form': form}) return render_to_response('transaction_add_page.html', variables) </code></pre> <p><strong>Template</strong></p> <pre><code>{% extends "base.html" %} {% block title %}Add Transactions{% endblock %} {% block head %}Add Transactions{% endblock %} {% block content %} &lt;form method="post" action="." &gt; {{ form.non_field_errors }} {{ form.errors }} {% for field in form %} &lt;div&gt; {{ field.errors }} {{ field.label_tag }}: {{ field }} &lt;/div&gt; {% endfor %} &lt;input type="submit" value="Add Transactions" /&gt; &lt;/form&gt; {% endblock %} </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload