简体   繁体   English

在没有身份验证应用程序的情况下使用 django 管理面板

[英]Use django admin panel without auth application

I've disabled authentication for Django admin panel as described here .我已禁用 Django 管理面板的身份验证,如此所述。
I would like to go further and completely skip django.contrib.auth migrations like users or groups tables.我想进一步 go 并完全跳过django.contrib.auth迁移,如用户或组表。

I've tried to remove django.contrib.auth from INSTALLED_APP and then I got error like below:我试图从INSTALLED_APP中删除django.contrib.auth ,然后出现如下错误:

RuntimeError: Model class django.contrib.auth.models.Permission doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

Is there any way to use Django admin panel without migrating django.contrib.auth migrations?有没有办法在不迁移django.contrib.auth迁移的情况下使用 Django 管理面板?

Short answer: No简短的回答:没有

Long answer: From a security standpoint there is absolutely no reason to ever do that, you will make your database open to everyone, with personal information.长答案:从安全的角度来看,绝对没有理由这样做,您将使您的数据库向所有人开放,包括个人信息。

Fortunately Django is smart enough to not let anyone do that and the requirements for the administration requires the auth middleware and the django.contrib.auth dependencies.幸运的是 Django 足够聪明,不会让任何人这样做,并且管理要求需要 auth 中间件和 django.contrib.auth 依赖项。

Again, you should not do that, you could tweak the Django framework and that could work, but you will need to write a lot of boilerplate and most package won't work.同样,您不应该那样做,您可以调整 Django 框架并且可以工作,但是您将需要编写大量样板文件并且大多数 package 将无法工作。

If you want to update your authentication backend Django make it pretty easy to do so: https://docs.djangoproject.com/en/4.1/topics/auth/customizing/如果你想更新你的身份验证后端 Django 让它很容易做到这一点: https://docs.djangoproject.com/en/4.1/topics/auth/customizing/

But be aware that would still need at least one auth backend for the admin to work.但请注意,管理员仍然需要至少一个身份验证后端才能工作。

django admin ( django.contrib.admin ) is tightly coupled with django.contrib.auth . django admin ( django.contrib.admin ) 与django.contrib.auth紧密耦合。 I didn't find a way to use use admin panel without auth app.我没有找到在没有auth应用程序的情况下使用管理面板的方法。

Nevertheless, I've found a solution, which met my expectations.尽管如此,我还是找到了一个符合我期望的解决方案。 I've set has_permission attribute of admin.site to True , as described here .我已将 admin.site 的has_permission属性admin.siteTrue ,如此所述。
Next, I've unregistered Group and User models from admin panel as described here .接下来,我从管理面板中注销了GroupUser模型,如此所述。 It's not clean solution, since django.contrib.auth migrations are still run, but normal user will not notice.这不是干净的解决方案,因为django.contrib.auth迁移仍在运行,但普通用户不会注意到。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM