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.
- [Answer]-How to get TastyPie fields.foreignkey to only return certain fields as apposed to resource uri or full object
- [Answer]-How to use models associated with a user in Django when rendering an HTML page
- [Answer]-Django REST API pagination: always return the same data
- [Answer]-Django rest framework OAuth2 Toolkit
- [Answer]-Server internal error with mod_wsgi and apache2
Source:stackexchange.com