Reputation: 379
I have in the html file a button defined as ;
<input type="submit" value="Log In" name="login_button" style="width: 109px; "/>
This button is on the sample.com . USer comes and clicking on the this button, then current web page, http://127.0.0.1:8000/sample
,is changed to the http://127.0.0.1:8000/sample2
, defined on the login.html. For this reason, I have done ;
def auth(request):
if 'login_button' in request.POST:
// redirect the web page to the sample2.com
return render_to_response('login.html', {} )
I have tried to redirect("http://127.0.0.1:8000/sample2
), but it is not worked. How can I go to another page.
Other web page defined on the this function
def message(request):
current_date_T = Template ("<p style=\"text-align: right;\">\
{{Date|truncatewords:\"8\"}}\
</p>")
# --
return HttpResponse(html)
url file
urlpatterns = patterns('',
('^sample2/$', message),
('^sample/$', auth),
)
page opened first is sample, in it there is a button. Sample2 will be called after button on the sample is clicked.
Upvotes: 1
Views: 101
Reputation: 32959
you simply need redirect
instead of render_to_response
. Try the following:
def auth(request):
if 'login_button' in request.POST:
# redirect the web page to the /sample2
return redirect('/sample2/')
else:
# Do something else
Upvotes: 2
Reputation: 39689
First of all define names to your urls:
urlpatterns = patterns('',
url('^sample2/$', message, name="message_view"),
url('^sample/$', authentication, name="auth_view"),
)
Then use url reverse resolution technique to get the url of a view using name of url:
def auth(request):
if request.method == 'POST':
// redirect the web page to the sample2.com
return redirect(reverse('message_view'))
return render_to_response('login.html', {} )
I don't know what is the purpose of redirect here. But thats how it works.
Upvotes: 1