user1561753
user1561753

Reputation: 357

Similar Django url patterns matches wrong one

It might be a regex issue or rule I'm not familiar with but I essentially have these 2 urls

(r'quote', quote),
(r'email/quote/$', sendQuote),

But when I go to mydomain.com/email/quote it keeps getting caught by the first one. Is there something I'm doing wrong?

Upvotes: 1

Views: 646

Answers (2)

schillingt
schillingt

Reputation: 13731

You need to specify the start of the regex using the ^ character. Similar to how $ specifies that it's the end of the regex, ^ will say that it's the start.

(r'^quote/$', quote),
(r'^email/quote/$', sendQuote),

Upvotes: 4

Sam
Sam

Reputation: 20486

I'm assuming it has to do with order. quote matches email/quote, so it gets matched first (ignoring email/quote/$). Try naming most-specific routes first, ending in a catch-all (if necessary):

(r'email/quote/$', sendQuote),
(r'quote', quote),
(r'.*', catchAll),

Upvotes: 1

Related Questions