Hi Kapil

The main reason I believe is because URL's are project global, rather than
per app. Yes the root urlconf can include URL's kept within apps, but
because it's a recursive data structure this isn't so easy.

For your use case I'd suggest either:

   - Using class based views, creating a subclass of View in your app with
   your middleware-like behaviour in its dispatch() method, and using that
   subclass in all your app's views
   - or similarly using a view decorator and ensuring it is applied to all
   views in your app

The final option is to use the middleware process_view method and inspect
if the view lives within the target app.

Hope that helps,

Adam

On Sun, 7 Jul 2019 at 16:42, Kapil Garg <kapilgarg1...@gmail.com> wrote:

> Hi, I am working on one django project and recently i had the requirement
> for a middleware. But i don't want this middleware to hook to every url
> served by the whole project but instead, only to one of the apps. I tried
> to look on the internet but everywhere there are hacks to implement it but
> not a in-built support from django. So i was curious why django doesn't
> provide support for app specific middleware or if it does then why there
> isn't any neat documentation about it. Thanks
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django developers (Contributions to Django itself)" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-developers+unsubscr...@googlegroups.com.
> To post to this group, send email to django-developers@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-developers.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-developers/1b8a2339-50fd-4b81-973f-9474787e3c6e%40googlegroups.com
> <https://groups.google.com/d/msgid/django-developers/1b8a2339-50fd-4b81-973f-9474787e3c6e%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>


-- 
Adam

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CAMyDDM1dWE6u%2BEggfNbgPQ_m3P9T-H6BKzjm-8qvbDXx9YW-%2Bg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to