Dear Ken,
First, let me just say ‘Thanks’ for your help.
The only dynamic part of my urls that I know of is what Django does with path conversion and regex
matching.
I tried the find, count, and replace methods for None and ‘’. exactly the same error
I tried retyping the path by hand - exactly the same error
I tried prepending ‘r’ for raw string. exactly the same error
I tried appending ‘$’. Now I get:
WARNINGS:
?: (2_0.W001) Your URL pattern ‘//$’ [name=‘codedetail_url’] has a route that contains ‘(?P<’, begins with a ‘^’, or ends with a ‘$’. This was likely an oversight when migrating to django.urls.path().
Note the raw string ‘r’ did not trigger a warning.
I tried appending ‘\Z’. exactly the same error, but now the regex pattern ends
with ‘(?P[^/]+)/\\Z\Z’]
I also returned to regex101 to test for \Z. But it turns out that if you put \Z in the pattern it
will match even before you put your string in. This is because \Z is a zero-width regex anchor that
means ‘end of input’ and is located before the newline, if there is one. At least I have expanded
my regex knowledge. Heretofore I thought ‘$’ was the only terminal anchor.
Here’s what is happening: When Django evaluates my path, it applies some sort of algorithm that
determines what regex pattern to apply, and then applies it. I was able to find this in the source
code:
https://docs.djangoproject.com/en/3.2/_modules/django/urls/converters/
class SlugConverter(StringConverter):
regex = ‘[-a-zA-Z0-9_]+’
The problem here is that this page vanishes from the docs for any Django version after 3.2. Also,
notice that the pattern applied in 3.2 != the one applied to my path, [^/]+. I am on 4.0.6.
Anyway, this pattern that Django is constructing and applying to my path also ‘helpfully’ adds \Z,
presumably as a terminus. Since Python uses the same escapes, that is turned into \Z. But, my guess
is that it is also prepending the raw string, (even though it does not show up in the
exception page - because that’s supposed to be good practice) with the result that the match
pattern fails because my path does not have literal \Z at the end.
Since I’d never seen \Z before, I did a lot of googling on this. I found two instances right here in
the forum of people with \Z in their patterns, but \Z was not discussed. So \Z has been around, but
I seem to be the only one it is messing with.
This is why I was hoping I could find it in the source and hack this behavior out of it, but I haven’t found it,
Suggestions?