English 中文(简体)
django的专栏被打破
原标题:Admin page on django is broken

I ve建立了一个有行政网页的django项目。 在发展的头两个星期里,它非常出色地工作,没有使用行政页,在我回头的时候,行政页被打破。 不管我做些什么,它还是打赢了让我站出来。

在进入用户名和PW之后,行政页总是说:

请输入正确的用户名和密码。 指出这两个领域都对个案敏感。

我对亚洲开发银行进行了检查:超级用户已经存在,而且已经是主动的,是超级用户,是所有真正的工作人员。 我先用斜体确保密码正确。 我多次抽取、删除并重整数据库,以确保没有错误。 我也把中间器、陶器、INSTALLED_APPS等两倍加检查,以确保它们能够适当建立起来。

就我所知,除了不让任何人在座外,行政网页的工作是完美的。

这里出现的任何想法,或其他试图解冻的方法? 我真的要靠这种ug子。

PS:如果是,Im利用南方进行非行移民,Django-social-auth为非银行的伐木者,以及当地制造与发展的隔_(我检查他们两人——那里的冲突)

最佳回答

This problem may be related to the Authentication Backends. Please check your settings files for the AUTHENTICATION_BACKENDS parameter.

价值如下:

AUTHENTICATION_BACKENDS = (
    ( django.contrib.auth.backends.ModelBackend ),
)

More information on the Official Django Documentation

问题回答

引证;测试。 py:

from django.contrib import auth

class AuthTestCase(TestCase):
    def setUp(self):
        self.u = User.objects.create_user( [email protected] ,  [email protected] ,  pass )
        self.u.is_staff = True
        self.u.is_superuser = True
        self.u.is_active = True
        self.u.save()

    def testLogin(self):
        self.client.login(username= [email protected] , password= pass )

然后用<代码>python管理进行测试。 py test <your_app_name>.Auth TestCase。 如果发放通行证,该系统就会发现用户名称和密码,以确保这些通行证可以接受。

我也有同样的问题,但是,在环境档案中悬挂BACKENDS旗帜并不是我的问题。 采用《Django 休息框架》,有点修改了密码,而没有打上密码,因此绕过了密码。 因此,它显示了无效的标志。

我得以通过简单的测试发现这一问题,以便通过类似的测试测试用户的生成:

from django.test import TestCase

from django.contrib import auth
from .models import *

class AuthTestCase(TestCase):
    def setUp(self):
        self.u = UserProfile.objects.create_user( [email protected] ,  iamtest ,  pass )
        self.u.is_staff = True
        self.u.is_superuser = True
        self.u.is_active = True
        self.u.save()

    def testLogin(self):
        self.client.login(username= [email protected] , password= pass )

It is also worth mentioning that I was creating a custom user named UserProfile

您是否使用习惯用户模型,是否在<编码>上添加这一模型? 这是我刚才的情况。

# Substituting a custom User model

AUTH_USER_MODEL = "app_custom_auth.User"

仅需要删除<代码>db.sqlite3,并再次迁移(python management)。 pymigration 然后:

python manage.py createsuperuser

重新设立账户。

You can do the following:

  • Enter your mysql (or other database console)
  • USE YourDATABASE;
  • SELECT * from auth_user;
  • watch is_staff and is_superuser item
  • UPDATE auth_user SET is_staff = "1" where username = "root";

然后,你可以再次 log!

答案是:

def create_superuser(self, username, email, password=None, **extra_fields):
    user = self.create_user(username, email, password=password, is_staff=True, **extra_fields)
    user.is_active = True
    user.save(using=self._db)
    return

<>代码>_active和is_staff 须在Django Admin上登录True,在以下情况下,您可在Django Admin上登录:

is_active   ✅
is_staff    ✅
is_superusr
is_active   ✅
is_staff    ✅
is_superusr ✅

In addition, even if is_superusr is True, you cannot log in Django Admin in these cases below because making is_superusr True gives the user all permissions except logging in Django Admin:

is_active
is_staff    ✅
is_superusr ✅
is_active   ✅
is_staff
is_superusr ✅
is_active
is_staff
is_superusr ✅

Another issue that can cause this is custom middleware, as it can interfere with the request/response cycle. This interference might not always throw explicit errors but can prevent processes like authentication from completing successfully.

Try disabling anytom mediumware in dings.py, 并且看这是否解决了你的问题。

For example, converting the default Django WSGIRequest to a DRF Request object has side effects that can cause standard Django views (including Django Admin) to have issues. For example, the below custom_logging_middleware.py would cause issues logging into Django Admin:

from rest_framework.request import Request
import logging


class RequestLoggingMiddleware:

    def __init__(self, get_response):
        self.get_response = get_response

    def __call__(self, request):
        start_time = time.time()
        logger = logging.getLogger(__name__)

        # Wrap the original request with DRF s Request, since the standard Django WSGIRequest doesn t have a .data attribute
        drf_request = Request(request)




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签