Héléna
Héléna

Reputation: 1095

django: redirecting to another app's view not properly

App1 containing the form, after user fulfills and submits the form, the page will redirect to "Result" which is defined in App2

def input(request):

    if request.method == 'POST': 
        form = Inputform(request.POST) 
        if form.is_valid(): 

            cd = form.cleaned_data
            print (cd['company'])
            print (cd['region'])
            return HttpResponseRedirect(reverse('result', args=(p.id,))) 

The url is as below:

urlpatterns = patterns('',
    url(r'^result/$','result.views.resultlist',name='result'),
    url(r'^input', 'inputform.views.input',name='input'),

The thing is if I run http://127.0.0.1:8000/result on the browser, it works properly. But once I fulfill the form and click the submit, the page will redirect to:http://127.0.0.1:8000/result.html. And then there is error showing: The current URL, result.html, didn't match any of these.

Any suggestion is highly appreciated. Thanks.

Upvotes: 2

Views: 93

Answers (1)

user1797792
user1797792

Reputation: 1189

try

return redirect('result', args=(p.id,))

Upvotes: 1

Related Questions