[Fixed]-Django included urls doesn't work

1👍

You have an error in calling the patterns() function:

urlpatterns = patterns(
    url(r'^subscribe/', subscribe),
)

patterns() accepts a view prefix as the first argument, if you pass an url() instance, this will not be used as a url pattern. If you had any other url patterns, this would give you an error, but in this specific case patterns() will simply return an empty list.

Since patterns() is deprecated, it is better to switch to the new-style url configuration, and use a list:

urlpatterns = [
    url(r'^subscribe/', subscribe),
]

Otherwise you’d have to pass a prefix as the first argument. Since you don’t actually use the prefix (you pass a view function, not the import location as a string), this would generally be the empty string ''.

👤knbk

0👍

if i try localhost:8000/sub/subscribe, it appends url with /lt/

Thats because your url pattern requires a trailing slash, which you haven’t provided

r'^subscribe/'  # Shouldn't have the slash or should be optional

Normally this wouldn’t be a problem since djangos APPEND_SLASH would help you out (if you’re using CommonMiddleware) but it would seem that django-cms has a catch-all redirect applied on your application to redirect to a locale.

👤Sayse

Leave a comment