I have a view that can be accessed by two different urls. The urls carry different variables. I was wondering if there was a way I can write something like this:
def view(request, x or y)
Is this possible?
Thanks,
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
To answer your direct question: no, you cannot write
def view(request, x or y)If you have two URLs that feed into the same view, you need to create to separate dispatchers in your urls.py file. If the two URLs send different types of data, you may consider using named parameters. For example:
From a style perspective, this probably isn’t the way to go. You should probably create two separate views. If they share logic, you should break that out into another function.