[Answer]-How to grab integers in a django url with a regex

1👍

Django always uses the first pattern that matches. For urls like /adm/list_users/assign_user_groups/4/grant_user_group/2/ the pattern that matches is the one named assign_user_groups, and grant_user_group is never used.

The problem is your use of .* in assign_user_groups, which is not specific enough, allowing all characters (including “/”) – this doesn’t really make sense, since you want to capture only numbers.

You could reverse the order of those two patterns, but what you should do is to make them more specific, changing all occurrences of .* to \d+.

Leave a comment