[Answer]-Two apps in one URL in Django

1👍

Your entire approach is mistaken, unfortunately. A view is responsible entirely for responding to a URL and returning a response. It simply doesn’t make sense to talk about having two views at a single URL.

If you need functionality provided by two apps within one URL, then think about abstracting the shared functionality into a utility method, or a template tag, or a context processor.

0👍

Add the dollar sign to the regex:

url(r'^$', 'joins.views.home', name='home'),

Without the $ the ^ regex matches all urls.

Of course the item.views.items will not work anyway (django executes the first matched url) but other views from item app will work just fine.

0👍

You want something like this I think:

 url(r'^joins/', include('joins.urls')),
 url(r'^items/', include('item.urls')),

see this: https://docs.djangoproject.com/en/1.7/topics/http/urls/#including-other-urlconfs

@s_spirit You want two views for one URL? To do that write a view that gets both models, pass both to your render function and make a template that displays what you want from each. Making two urls the same will only do what the first match does – joel goldstick 2 hours ago

Leave a comment