1

This seems to not work in django:

urlpatterns = [
    url(r'^%s/admin/' %(BASE_PATH), include(admin.site.urls)),
    url(r'^%s/$' %(BASE_PATH), home_view),
    url(r'^%s/ping/$' %(BASE_PATH), ping),
    url(r'^%s/echo/$' %(BASE_PATH), echo),
    url(gcd_str, gcd),
]

If I set the BASE_PATH to 'test' and go to http://host/test/echo I get a 404 error but my paths look like this on the error page:

^/test/admin/
^/test/$
^/test/ping/$
^/test/echo/$
^/test/gcd/$

If I hard-code like this it works:

urlpatterns = [
    url(r'^test/admin/', include(admin.site.urls)),
    url(r'^test/$', home_view),
    url(r'^test/ping/$', ping),
    url(r'^test/echo/$', echo),
]

I guess that the pattern does not get interpolated correctly, if I use a string without the r it seems to behave the same.

1 Answer 1

1

The issue is that you are setting BASE_PATH to

/test

Where as when you hardcode then you write it as

test

The starting / makes all the difference, as the url pattern expects ( as per BASE_PATH is the one that starts with

^/test/admin/
|| |
|| matches test
|matches /
matches start of the pattern
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, can't believe I didn't notice that.

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.