Reversing namespaced URLs in Django: multiple instances of the same app

前端 未结 5 1838
鱼传尺愫
鱼传尺愫 2020-12-30 07:09

I\'ve been working with Django for a while now (currently on version 1.2), but just recently started working on an app that needs to support multiple instances. E.g., the p

5条回答
  •  情深已故
    2020-12-30 07:21

    If you're not too tied to namespaces, you could instead write your urls.py to be like:

    urlpatterns = patterns('',
        (r'^(P/)', 'controllers.route_me'),
    )
    

    This will make a call to the controllers.route_me function and pass it the request, plus the string 'instance', which you could handle this way:

    # (in controllers.py)
    def route_me(request, instance):
        # you now have complete control, and do what you need to do with the 'instance' and 'request' vars
        pass
    

提交回复
热议问题