I am trying to use a single application to satisfy multiple URLs. That is, I want url /blog/ and /job/ use the same application, but different types. There are several ways to do this, I am sure, but none of them seem very clean. Here is what i am doing right now
# /urls.py urlpatterns = patterns("", (r"^(blog|job)/", include("myproject.myapp.urls")), ) # /myapp/urls.py urlpatterns = patterns("myproject.myapp.views", (r"^(?P<id>\d+)/edit/$", "myproject.myapp.views.edit"), (r"^(?P<id>\d+)/delete/$", "myproject.myapp.views.delete"), (r"^(?P<id>\d+)/update/$", "myproject.myapp.views.update"), (r"^insert/$", "myproject.myapp.views.insert"), ) urlpatterns += patterns("", (r"^(?P<object_id>\d+)/$", "django.views.generic.list_detail.object_detail", info_dict, "NOIDEA-detail"), (r"^/$", "django.views.generic.list_detail.object_list", info_dict, "NOIDEA-community"), ) # /myapp/views.py def edit(request, type, id): if (type == "blog"): editBlog(request, id) else (type == "job") editJob(request, id) def editBlog(request, id): # some code def editJob(request, id): # some code
I ended up breaking it all down into several models and browsing the files to make the code cleaner, but the above example doesnβt take into account things like reverse URL lookups that breaks all calls to my template {% url %} .
Initially, I had blogs, jobs, events, contests, etc., all of which live in their applications, but all of their functions are so similar that it makes no sense to leave it this way, so I tried to combine them ... and it happened. Do you see the names "NOIDEA-detail" and "NOIDEA-community" in my general views? Yes, I do not know what to use there: - (