Django: Submit points at wrong url

944 views Asked by At

I have two forms in the same app, one is based on the Django FormWizard and "normal" form. The "normal" form works fine, but when I use the Wizard created form, the user gets redirected to the normal form and it does not proceed to the next form step.

The Wizard Form is located under ../app/NewEntry. When I encounter the 2nd stage of the form and I click on submit, then I get redirected to ../app, even so the html code says action='.' in the html file.

Since it only happens at the second stage, I figured it has something to do with the render_template function, but I do not see why.

The forms.py looks like:

  1 from django.http import HttpResponseRedirect
  2 from django.contrib.formtools.wizard import FormWizard
  3 from django import forms
  4 from django.forms.widgets import RadioSelect
  5 from geoCode import getLocation
  6 from renooble.pp.models import Project
  7
  8 class appStart(forms.Form):
  9     location = forms.CharField()
 10     CHOICES = [(x, x) for x in ("cars", "bikes")]
 11     technology = forms.ChoiceField(choices=CHOICES)
 12
 13 class appLocationConfirmation(forms.Form):
 14    locations = forms.CharField()
 15
 16 class appData(forms.Form):
 17     capacity = forms.IntegerField()
 18
 19 class appWizard(FormWizard):
 20
 21     def render_template(self, request, form, previous_fields, step, context=None):
 22         if step == 1:
 23             location = request.POST.get('0-location')
 24             address, lat, lng, country = getLocation(location)
 25             form.fields['locations'] = forms.ChoiceField(widget=RadioSelect(), choices = [])
 26             form.fields['locations'].choices = [(x, x) for x in address]
 27         return super(appWizard, self).render_template(request, form, previous_fields, step, context)
 28
 29
 30     def done(self, request, form_list):
 31         # Send an email or save to the database, or whatever you want with
 32         # form parameters in form_list
 33         return HttpResponseRedirect('/contact/thanks/')
 34
 35 class reMapRedefine(forms.Form):
 36     LIMIT_CHOICES = (
 37     ('1', '1'),
 38     ('2', '2'),
 39     ('30', '30'),
 40     )
 41     numberLimit = forms.CharField(widget=forms.Select(choices=LIMIT_CHOICES))
 42
 43     country_list = [('Worldwide', 'Worldwide')]
 44     country_list = country_list + [(query.country, query.country) for query in Project.objects.all()]
 45     country = forms.ChoiceField(required=False, label='Country', choices=country_list)

The urls.py are defined as follows

######################################################
     (r'^app/$', app_startpage),
     (r'^app/NewEntry$', appWizard([appStart, appLocationConfirmation, reMapData])),
######################################################

So, as soon as appLocationConfirmation is called, the URL changes from /app/NewEntry (url for the Wizard) to /app. I do not understand why?

Any help or clarification is heavily appreciated. Thank you.

1

There are 1 answers

0
Fareed On BEST ANSWER

I've encountered a similar problem before, due to a missing final forward slash. I doubt the original poster will respond at this late date, but for anyone who stumbles upon this question, double check that your URLconf includes a trailing slash, like so:

r'^reMap/NewEntry/$' rather than r'^reMap/NewEntry$'.