Django-filer,与管理员“分离"的URL [英] Django-filer, URL that is 'seperate' from admin
问题描述
我正在尝试在我的网站上设置django-filer.我不知道如何将URL与网站上的管理站点分开.
localhost:8000/admin/filer/folder/
现在是它想去的地方,这当然需要某人在/admin部分具有完整的管理员访问权限.我希望他们拥有文件管理者访问权限并能够看到该网站.我的基本urls.py为:
urlpatterns = [路径("admin/",admin.site.urls),path('accounts/',include('accounts.urls')),#新path('accounts/',include('django.contrib.auth.urls')),path('filer/',include('filer.server.urls')),]
虽然转到localhost:8000/filer却什么也没做?我希望我可以在django网站上创建本地的小保管箱功能,注册用户可以在其中使用它,尽管他们不必在/admin
中是admin.这甚至有可能吗?我根本没有在Filer的文档中看到它?
当我查看
现在,我们需要处理权限.为此,我正在使用组权限"方案.所以,
- 创建组
- 向该组添加所有
filer 个应用权限 - 将普通用户添加到 Filer 组
最后,对于普通用户,Django Admin看起来像
I am trying to set up django-filer on my website. I cannot figure out how to get the URLS to be separate from the admin site on the website.
localhost:8000/admin/filer/folder/
Is where it wants to go now, which of course requires someone to have complete admin access in the /admin portion. I want them to have just filer access and be able to see the site. I have my base urls.py as:
urlpatterns = [
path('admin/', admin.site.urls),
path('accounts/', include('accounts.urls')), # new
path('accounts/', include('django.contrib.auth.urls')),
path('filer/', include('filer.server.urls')),
]
Going to localhost:8000/filer does nothing though? I was hoping I was able to create a local little dropbox functionality with my django website where registered users can use it, though they don't have to be admin in the /admin
Is this even possible? I didn't see it in the documentation for filer at all?
When I looked into the source code of django-filer I felt, it will be very hard to re-implement these kinds of operations outside the Django Admin.
So, I would like to implement a different solution... Allow non-staff users to access the Django admin, but only to this particular app
For that, we need to override the default admin site.
# myproject/admin.py
from django.contrib import admin
from django.contrib.auth.forms import AuthenticationForm
class MyAdminSite(admin.AdminSite):
login_form = AuthenticationForm
def has_permission(self, request):
return request.user.is_active
# myproject/apps.py
from django.contrib.admin.apps import AdminConfig
class MyAdminConfig(AdminConfig):
default_site = 'myproject.admin.MyAdminSite'
# myproject/settings.py
INSTALLED_APPS = [
...
'myproject.apps.MyAdminConfig', # replaces 'django.contrib.admin'
...
]
Notes:
- Why override
login_form
andhas_permission(...)
?- By default Django checks
is_staff
flag. In our cases, we need to allow all authenticated users
- By default Django checks
As of now, for a non-staff user can log in to the Django Admin and he will able to see an empty Django dashboard as below
Now we need to handle the permissions. For that, I am using Group Permissions schemes. So,
- Create a Group
- Add all
filer
app permissions to the group - Add normal user to the Filer group
and now finally, for a normal user, the Django Admin will look like,
这篇关于Django-filer,与管理员“分离"的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!