I have a little form:
<form action="#" method="post">
{% csrf_token %}
<label>Company Number:</label>
<input type="text" name="company" placeholder=""/><br>
<input type="submit" id="register value=" OK" />
</form>
Which is mapped like this:
url(r'^userfilt/insertForm/$', views.insertForm, name='insertForm'),
Now after submitting this form, I want to get back to the main view:
url(r'^userfilt/$', views.userfilt, name='userfilt')
URL mapping file:
app_name = 'SSO_Management_POC'
urlpatterns = [
url(r'^$', views.IndexView.as_view(), name='index'),
url(r'^user/$', views.user, name='user'),
url(r'^userfilt/$', views.userfilt, name='userfilt'),
url(r'^userfilt/insertForm/$', views.insertForm, name='insertForm'),
#url(r'^updateForm/$', views.updateForm, name='updateForm'),
url(r'^(?P<pk>[0-9]+)/$', views.DetailView.as_view(), name='detail'),
url(r'^(?P<pk>[0-9]+)/results/$', views.ResultsView.as_view(), name='results'),
url(r'^(?P<question_id>[0-9]+)/vote/$', views.vote, name='vote'),
]
The main view is like this (but I don't think this code is related to the problem..):
def userfilt(request):
if request.GET.get('create'):
return HttpResponseRedirect('insertForm')
if request.GET.get('update'):
print request.GET.get('pk')
return render(request, 'SSO_Management_POC/updateForm.html')
if request.method == 'POST':
form = UserForm(request.POST)
val = request.POST.get('my_textarea')
return render(request, 'SSO_Management_POC/userfilt.html',
{'top_user': TopUser.objects.filter(user_name__regex=val)})
else:
print '4'
return render(request, 'SSO_Management_POC/userfilt.html')
Now the call that is killing me happens when N submit the form, N just wanna get back to the main page calling it with a POST, like a always did!
return render(request, "SSO_Management_POC/userfilt.html")
I do it like this, but the problem is that the URL has not been reset.. and results in this,
http://127.0.0.1:8000/SSO_Management_POC/userfilt/insertForm/#
Resulting in every operation I make on that page not work because it's not mapped anymore
I mean, it should be:
but instead it is
To try to explain my issue better..
I go to the main page (http://127.0.0.1:8000/SSO_Management_POC/userfilt/)
"GET /SSO_Management_POC/userfilt/ HTTP/1.1" 200 2648
Then I click on the create User to call the form, it brings me to: (http://127.0.0.1:8000/SSO_Management_POC/userfilt/insertForm/)
"GET /SSO_Management_POC/userfilt/insertForm/ HTTP/1.1" 200 1549
Than I submit the form and I would like to get back to the main page, and here comes the thing I don't understand: it bring me here
http://127.0.0.1:8000/SSO_Management_POC/userfilt/insertForm/#
But I want to go here
http://127.0.0.1:8000/SSO_Management_POC/userfilt
This is again the code:
return render(request, "SSO_Management_POC/userfilt.html")
This is the call made:
"POST /SSO_Management_POC/userfilt/insertForm/ HTTP/1.1" 200 2648
I tried with render, with HttpResponseRedirect and so on... But always it happened the URL I'm calling with the previous one, I want it to be reset, I want it to be ../ !!!
The only thing that work for me is:
return redirect("../")
but
- this is dirty
- this does not permit to make a POST call!
Thanks to Daniel, I fixed it like this:
return redirect('/SSO_Management_POC/userfilt')
But it still give me same issue with:
return render(request,'/SSO_Management_POC/userfilt')
Getting me to http://127.0.0.1:8000/SSO_Management_POC/userfilt/insertForm/