0

I want to use a part of the data from the form to use in my HttpResponseRedirect method, but I can't seem to manipulate the data once I get it from the form.

view.py:

if request.method == 'POST':
    form = ReviewForm(request.POST)

    if form.is_valid():
        form.save(commit=True)

        joint = form.cleaned_data['place']
        //Gets me the name of the joint. 
        //I need to clean up the name so I can use it in a URL

        joint = joint.replace('_', ' ')
        joint = joint.replace('00', "'")
        joint_url = joint.replace('11', "/")

        return HttpResponseRedirect('/burgers/place/' + joint_url)

But when someone submits a name like "Hotdog House " The name of the place is returned, and all of my cleaning doesn't stick. I would expect to get Hotdog_House - but I get Hotdog House.

user1410712
  • 185
  • 1
  • 2
  • 10

1 Answers1

1

You're using the replace method wrong: if you want to convert from a space to an underscore, you should put them in the other way round:

joint = joint.replace(' ', '_')

Also note that this code should really be in the form's clean_place method, so that the data is converted by the form itself.

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895