Python 如何完全禁用Django admin的身份验证

Python 如何完全禁用Django admin的身份验证,python,django,django-rest-framework,postgis,Python,Django,Django Rest Framework,Postgis,我有一个Django服务器(使用PostGis),我想禁用与身份验证相关的所有功能: 当输入管理员时,不需要身份验证 在管理窗口中隐藏用户/组 在网上搜索之后,我尝试了& 它确实让我得到了我希望的结果,直到我试图通过管理员添加一个对象。然后我得到一个整数错误: insert or update on table "django_admin_log" violates foreign key constraint "django_admin_log_user_id_c564eba6_fk_au

我有一个Django服务器(使用PostGis),我想禁用与身份验证相关的所有功能:

  • 当输入管理员时,不需要身份验证
  • 在管理窗口中隐藏用户/组
在网上搜索之后,我尝试了&

它确实让我得到了我希望的结果,直到我试图通过管理员添加一个对象。然后我得到一个
整数错误

insert or update on table "django_admin_log" violates foreign key constraint "django_admin_log_user_id_c564eba6_fk_auth_user_id"
DETAIL:  Key (user_id)=(1) is not present in table "auth_user".
我试着用像这样的解决方案来解决它,但没有任何帮助

我不介意有一个全新的解决方案,只要最终目标已经实现


感谢大家,因为Django项目正在dockers中运行,并且可以在用户已经存在或不存在的情况下进行部署。我最后做了以下工作:

# Create superuser for admin use in case it doesn't exist
try:
    User.objects.get_by_natural_key('admin')
except User.DoesNotExist:
    User.objects.create_superuser('admin', 'admin@comapny.com', '123456')
希望有一天这能帮助别人。充分利用:

from django.contrib import admin
from django.contrib.auth.models import User, Group


# We add this so no authentication is needed when entering the admin site
class AccessUser(object):
    has_module_perms = has_perm = __getattr__ = lambda s,*a,**kw: True

admin.site.has_permission = lambda r: setattr(r, 'user', AccessUser()) or True

# We add this to remove the user/group admin in the admin site as there is no user authentication
admin.site.unregister(User)
admin.site.unregister(Group)

# Create superuser for admin use in case it doesn't exist
try:
    User.objects.get_by_natural_key('admin')
except User.DoesNotExist:
    User.objects.create_superuser('admin', 'admin@optibus.co', '123456')

您需要实际创建id为1的用户。