0

Is there a way to match url to get result based on dynamic queries in Django without having to declare multiple urlpatterns. What I mean is the same urlpatterns to match something like

localhost:8000/person/?name=john&age=10&gender=male
localhost:8000/person/?age=10&gender=male&name=john
localhost:8000/person/?gender=male&name=john&age=10
0

1 Answer 1

3

You are confusing url GET parameters with url regex matching patterns.

According to your question, this url:

url(r'^person/', some_view, name='person'),

should match all the above urls.

Inside the some_view view, you can get each url GET parameter like this:

def some_view(request):
    name = request.GET.get('name', '')
    age = request.GET.get('age', '')
    gender = request.GET.get('gender', '')
    # return an Http Response (always)
Sign up to request clarification or add additional context in comments.

Comments

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.