[Answer]-Django Url Conf Dynamic Url Conflict

1๐Ÿ‘

โœ…

I would suggest writing a helper view function, which checks whether the inputted url corresponds to a company or a category, and then redirecting the request to the appropriate page.

url(r'^prizes/', include(patterns('prizes.views',
    url(r'^$', 'PrizeStore_Index', name="prizestore"),
    url(r'^(?P<slug>[\w-]+)/$', prizehelper, name="prizehelper),

where, you can check within prizehelper, if it is a company or a category and move on accordingly.

Another approach could be, to change your url structure, and reflect which type of url it is

url(r'^prizes/', include(patterns('prizes.views',
    url(r'^$', 'PrizeStore_Index', name="prizestore"),
    url(r'^company/(?P<slug>[\w-]+)/$', PrizeCompanyDetailView.as_view(), name="prizecompany"),
    url(r'^category/(?P<slug>[\w-]+)/$', 'PrizeType_Index', name="prizetype"),
๐Ÿ‘คAnshul Goyal

0๐Ÿ‘

Have a single urlconf entry that goes to a view which figures out which type is being examined and then dispatches to the appropriate view for that type.

Leave a comment