0

I am trying to implement a redirection script. The format of the url would be

http://localhost:8000/key/url=http://google.com

From the above, I want http://google.com

When some user visits the above url, it hits the urlpatters defined in the urls.py

url(r'^key/url=(.*)', 'homepage.views.redirectquerystring', name="Redirect"),

I am trying to get the url http://google.com using the below view

def redirectquerystring(request):
    para = request.GET.get('url','')

But when I do this, I am getting the following error:

TypeError at /key/url=http://google.com
redirectquerystring() takes exactly 1 argument (2 given)

Am I doing some mistake here.

Thanks.

2 Answers 2

3

This is much simpler than you think it is.

You're trying to pass http://google.com as a parameter, but you're not giving your view a place to receive that parameter.

You need to define your view as def redirectqyrystring(request, url):

You don't need to get the url from the request now, it's already there in the variable url

Sign up to request clarification or add additional context in comments.

Comments

3

You should "capture" the url param using the urlpatterns regex like this:

url(r'^key/url=(?P<url>.*)', 'homepage.views.redirectquerystring', name="Redirect"),

this way your view receives a parmeter named url, which contains the captured url get param.

2 Comments

def redirectquerystring(request, url):
django is beautiful, isn't it?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.