But if I use the pattern:urlpatterns = [
url(r'^blank/.*$', views.BlankMore, name='blankMore'),
]
I can enter:
localhost:8000/uA/blank/
and the pattern will match, but if I enter:
localhost:8000/uA/blank/abc
I get an error message: "Page not found (404)"
I could be doing something wrong here, however I am more inclined to believe this is a bug. My error? Bug?
Problem 2 - Similar to problem 1 except I would like to capture a value in the URLIf I use the pattern:urlpatterns = [
url(r'^pass/val(?P<val>.*)/$', views.PassVal, name='passval'),
]
and I enter the url:
http://localhost:8000/uA/pass/val12/
the browser displays the value for 'val' as 12.
But if I use a url pattern like this:urlpatterns = [
url(r'^pass/(?P<val>.*)/$', views.PassVal, name='passval'),
]
and I enter the url:
http://localhost:8000/uA/pass/val12/
the browser displays the value 'val12', as expected.
but if I enter the url:
http://localhost:8000/uA/pass/?abc=12/
I get an error message: "Page not found (404)"
What I would like to happen in this case is that the value "?abc=12" be passed to the view. I know the '?' is a special character here but not to the browser or Django. My expectation is that the browser would pass it as part of the request and that Django would do likewise. Is this a bug? My error?
On Monday 19 June 2017 16:43:12 James Schneider wrote:
> But if I use the pattern:
>
> *urlpatterns = [ *
> * url(r'^blank/.*$', views.BlankMore, name='blankMore'),*
> *]*
>
> I can enter:
>
> localhost:8000/uA/blank/
>
> and the pattern will match, but if I enter:
>
> localhost:8000/uA/blank/abc
>
> I get an error message: "Page not found (404)"
>
> I could be doing something wrong here, however I am more inclined to
> believe this is a bug. My error? Bug?
>
>
> This appears to be working as designed. Your interpretation of the
> regex algorithm behavior is incorrect. In most cases, the matching
> algorithm will take the first and almost always shortest match (there
> are probably some exceptions nestled deep in the Python re module).
What did you base this on? Certainly not the python docs or behavior of any pcre based library.
Regular expressions are capitalist: greedy by default.
The qualifiers *? are there especially to make a match non-greedy.
Quick test:
pcregrep -o '^.*:' /etc/passwd
versus:
pcregrep -o '^.*?:' /etc/passwd
> The .* modifier means "match any character (.) zero or more times
> (*)". Since blank/ matches the .* zero times, it is a match for your
> expression.
And his problem is that it does *not* match. Not that it does.
--
Melvyn Sopacua
What did you base this on? Certainly not the python docs or behavior of any pcre based library.
Regular expressions are capitalist: greedy by default.
The qualifiers *? are there especially to make a match non-greedy.
Quick test:
pcregrep -o '^.*:' /etc/passwd
versus:
pcregrep -o '^.*?:' /etc/passwd
> The .* modifier means "match any character (.) zero or more times
> (*)". Since blank/ matches the .* zero times, it is a match for your
> expression.
And his problem is that it does *not* match. Not that it does.
On Tuesday 20 June 2017 18:08:02 James Schneider wrote:
> > And his problem is that it does *not* match. Not that it does.
>
> And for that I think my statement still stands that Django is
> stripping the last portion of the URL as a GET argument. I'm betting
> that
> requests.GET.get('abc') will return '12/' per the last example from
> the OP.
Yes, but for the first problem, r'^blank/.*$' should match blank/abc and generates a 404. I think the matching isn't the problem and the 404 is caused either by ordering issue in urlpatterns (first match wins, no others are tried) or with the view itself (get_object_or_404).
You are correct that urlpatterns are only matched against request.path. This excludes the query string.
--
Melvyn Sopacua