Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The way you have written your view, to display form errors, in your <code>web/error.html</code> template, simply output the errors:</p> <pre><code>{%if e %} You had some errors in your submission!&lt;br /&gt; {{ e }} {% endif %} </code></pre> <p>However, you don't have explicitly pass the errors list, it is part of the form itself. A bit of simplification:</p> <pre><code>variables = RequestContext(request, {'form': form}) return render_to_response('web/error.html', variables) </code></pre> <p>Then, in your template:</p> <pre><code>{% if form.errors %} You have some errors!&lt;br /&gt; {{ form.errors }} {% endif %} </code></pre> <p>For the second part of your question - to display the django date time widget - things get a bit more involved:</p> <pre><code># First, you need to import the widget: from django.contrib.admin.widgets import AdminSplitDateTime from django.forms import TextField # In your form class, you have to specify the widget # for the field. class AnimalForm(forms.ModelForm): pub_date = models.TextField(widget=AdminSplitDateTime) class Meta: model = Animal </code></pre> <p>In order for this to work though, you have to make sure your admin media directory is accessible from your project (since all the javascript and css is included there). You'll also to have make sure that all the stylesheets are also added. It is much easier (and simpler) to use your own javascript form widget from your preferred library.</p> <p>Finally, as stated in the <a href="https://docs.djangoproject.com/en/dev/topics/forms/modelforms/#overriding-the-default-field-types-or-widgets" rel="nofollow">documentation</a>, if you override any fields, you need to add all the other validation logic yourself:</p> <blockquote> <p>If you explicitly instantiate a form field like this, Django assumes that you want to completely define its behavior; therefore, default attributes (such as max_length or required) are not drawn from the corresponding model. If you want to maintain the behavior specified in the model, you must set the relevant arguments explicitly when declaring the form field.</p> </blockquote>
 

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