0

My problem is the following: Inside my urls.py I have defined these url patterns:

url(r'^image/upload', 'main.views.presentations.upload_image'),
url(r'^image/upload-from-url', 'main.views.presentations.upload_image_from_url'),

the problem is when I call from my browser the URL myowndomain:8000/image/upload-from-url Django always execute the first pattern (r'^image/upload')

Is there any solution to my problem?

2 Answers 2

1

Django uses the first matching pattern, and your ^image/upload pattern doesn't include anything to stop it matching the longer text. The solution is to require that your pattern also match the end of the string:

r'^image/upload$'

By convention, Django URLs generally have a trailing slash as well, but that's not strictly required:

r'^image/upload/$'
Sign up to request clarification or add additional context in comments.

Comments

1

You need to insert the dollar sign "$" at the end of the pattern. The dollar sign is a character that represents position. In the case of regex, this is the end of the string. Because both image/upload and image/upload-from-url match what you're looking for, you need to explicitly say where to stop in the pattern.

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.