I’ve got a Django forms page, set up in the classic Django way to show a form for a GET request and to handle form submission for a POST request, and return errors for invalid data.
def create_trial(request):
trial_form = TrialForm()
if request.method == 'POST':
if request.POST['form'] == 'trial_create':
trial_form = TrialForm(request.POST)
if trial_form.is_valid():
# etc etc
return render_to_response(template, {'trial_form': trial_form},
context_instance=RequestContext(request))
Now, I need to create a static HTML page, located on a different subdomain, that POSTs directly into this Django form.
Obviously, if all the data is okay, then that’s fine – the HTML page will just redirect to the Django success message.
However, what will happen if the Django form rejects some of the data? What will my user see?
What would be ideal is if they were redirected to the Django form (in the Django subdomain) with the data pre-filled and the relevant error messages showing, but I don’t know if that’s actually possible.
Please could anyone advise?
Answering my own question: No problem – on testing, it all Just Works in Django.
A failed response redirects to the form on the Django subdomain, with the errors pre-filled. I heart Django!