[Answered ]-Regex urlconf in django 1.8 won't work

2👍

Your patterns are not working because such patterns break the Django’s reverse url resolution functionality.

Reversing urls takes a view and it’s params and determines what url which that view has. With patterns like your (polls/)|(pollapp/) Django is unable to tell which version of the url you want. Should it be /polls/yourview or /pollapp/yourview ?

Two fix that you could include both patterns in your urlconfig:

url(r'^polls/', include('pollapp.urls')),
url(r'^pollapp/', include('pollapp.urls')),

However i strongy advice to chose only pattern (polls or pollsapp) to keep your code simple and avoid duplication.

0👍

Your attempt isn’t a valid regex for matching what you want. Try something like:

url(r'^poll(s|app)/', include('pollapp.urls'))
👤Ben

0👍

I think you can just:

url(r'^polls/', include('pollapp.urls')),
url(r'^pollapp/', include('pollapp.urls')),

Then both polls/ and pollapp/ will work.

You can’t have both in one url as Django won’t know which to reverse in some situations.

👤pythad

Leave a comment