Yes - but it doesn’t depend on some hidden feature of Django. It’s 

A Django View is just a function that accepts a request + args, and returns a 
response. That view can, itself, call other functions - including other 
functions that can act as views. So, you could write a “switch statement” view:

def switch_view(request, arg1, arg2):
    if client_app_name == ‘xxx’:
        return xxx.view(request, arg1, arg2)
    else:
        return base_view(request, arg1, arg2)

The logic of exactly how to manage the “switch” is entirely up to you.

Depending on how you set up your client sub-packages, you might even be able to 
use import logic to your advantage:

def switch_view(request, arg1, arg2):
    try:
        client_module = importlib.import_module(‘project.%s.emailer.view’ % 
client_name)
        return client_module.view(request, arg1, arg2)
    except ImportError:
        return base_view(request, arg1, arg2)

Yours,
Russ Magee %-)

> On 11 Aug 2017, at 5:32 am, Khai Weng Au Yeong <aykhaiw...@gmail.com> wrote:
> 
> Not sure if this has been covered before, but I was thinking about this for 
> awhile.
> 
> Is there a way to dynamically select a View to be used by a URL without 
> having to replicate the URL dispatcher over and over via a "superceding" like 
> method. Like for example, in my project (let's say it's generic), if I have 
> "BaseEmailer" at "<project_root>.emailer.views" and I have a client with a 
> special-case need installed at "<project_root>.clients.emailer.views", can I 
> get Django to dynamically select it just based off this logic: if 
> client-app-name = base-app-name?
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users+unsubscr...@googlegroups.com 
> <mailto:django-users+unsubscr...@googlegroups.com>.
> To post to this group, send email to django-users@googlegroups.com 
> <mailto:django-users@googlegroups.com>.
> Visit this group at https://groups.google.com/group/django-users 
> <https://groups.google.com/group/django-users>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/bc82a384-dec5-4f0a-8cb4-2e4c642b3677%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/django-users/bc82a384-dec5-4f0a-8cb4-2e4c642b3677%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/F5301BC5-CD27-4EC9-A62E-9E32DFB1B22C%40keith-magee.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to