I have a view that either displays a form or a ‘thank you’ page (if the form submission was successful). I am using redirect with a url that I have tested working to display the thank-you page.
def form8(request):
form = UserInfoForm(request.POST or None)
if form.is_valid():
form.save()
return redirect('/sjwork/thanks')
return render(request, 'form8.html', {'form': form})
However, when the form is successfully submitted django give the error:
ViewDoesNotExist at /sjwork/form8
Could not import views. Error was: No module named views
As said, I can go to localhost:8000/sjwork/thanks directly and it displays the thank-you page. According to documentation I can use a hard-coded url like this. I tried alternatives, too (giving the view, using a full url like http://google.com) – nothing works. I must be missing something basic here. Would appreciate if someone can explain what is going on here. Thanks.
The app ‘sjwork’ has the following in its urls.py:
url(r'^$', 'views.home', name='home'),
url(r'^thanks$', 'sjwork.views.thanks'),
url(r'^form8$', 'sjwork.views.form8', name='form8'),
whereas the project urls.py contains:
url(r'^sjwork/', include('formtest.sjwork.urls')),
Looks like error is related to this pattern.
Try removing it and try again.
Also, Could you include your import statements in your question.