#30344 closed Cleanup/optimization (wontfix)
Converted serve static to class base views
Reported by: | Tom Turner | Owned by: | nobody |
---|---|---|---|
Component: | contrib.staticfiles | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Florian Apolloner | Triage Stage: | Unreviewed |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Hi I wanted to override the serve static I couldn't do this as it wasn't class based
pull request https://github.com/django/django/pull/11193
Change History (4)
comment:1 by , 6 years ago
Cc: | added |
---|---|
Component: | Uncategorized → contrib.staticfiles |
Version: | 2.2 → master |
comment:2 by , 6 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
Type: | Uncategorized → Cleanup/optimization |
Agreed with Florian, just transforming to a class-based view without making "entry-point" method to override for real use cases doesn't make much sense. Maybe you could discuss that first on the django-developers mailing list.
comment:3 by , 6 years ago
I agree it not backward compatible however that an easy fix more me to do I wasn't going to do unless the ticket was accepted. I also agree the patch needs some tidying up in regards to code comments
I will now give more details why I wanted this patch. I am the maintainer of a project called Django Tenants http://github.com/tomturner/django-tenants which allows you to have tenants in Django ie a.mydomain.com and b.mydomain.com. The problem I have is that on the different domains I want to serve different static files. The problem is I cant pick up the domain and set the correct tenant. I believe this could do this easier if the serve static is class based. Making the serve static class base will not affect users of Django and I know a lot of other areas in Django have been converted to class base views such as the admin
I believe one could override the entry point with something like this in the url
re_path(r'^site_media/(?P<path>.*)$', static.ServeStatic.as_view(document_root=media_dir, show_indexes=True))
I know server static should only be used for development use only.
Hopefully you now see the use case I want to do.
comment:4 by , 6 years ago
You are saying:
The problem is I cant pick up the domain and set the correct tenant for static files. I believe this could be done easier if the serve static is class based.
I do not see how your changes would make this any easier, or why this would not be possible with the current function based view.
What exactly couldn't you override/change? Changing views to functions based views just so they are a class is probably not enough. Also this change is currently highly backwards incompatible.