2017-10-04 31 views
-1

管理ページにログインしようとしたときにこのエラーが発生しました。/admin/login/'tuple'のAttributeErrorオブジェクトに 'rsplit'属性がありません

AttributeError at /admin/login/ 

'tuple' object has no attribute 'rsplit' 

Request Method:  GET 
Request URL: http://127.0.0.1:8000/admin/login/?next=/admin/ 
Django Version:  1.10 
Exception Type:  AttributeError 
Exception Value:  

'tuple' object has no attribute 'rsplit' 

Exception Location:  C:\Users\Adila\Envs\tryFOUR\lib\site-packages\django\utils\module_loading.py in import_string, line 15 
Python Executable: C:\Users\Adila\Envs\tryFOUR\Scripts\python.exe 

トレースバック:

トレースバック:

File "C:\Users\Adila\Envs\tryFOUR\lib\site-packages\django\core\handlers\exception.py" in inner 
    39.    response = get_response(request) 

File "C:\Users\Adila\Envs\tryFOUR\lib\site-packages\django\core\handlers\base.py" in _get_response 
    187.     response = self.process_exception_by_middleware(e, request) 

File "C:\Users\Adila\Envs\tryFOUR\lib\site-packages\django\core\handlers\base.py" in _get_response 
    185.     response = wrapped_callback(request, *callback_args, **callback_kwargs) 

File "C:\Users\Adila\Envs\tryFOUR\lib\site-packages\django\views\decorators\cache.py" in _wrapped_view_func 
    57.   response = view_func(request, *args, **kwargs) 

File "C:\Users\Adila\Envs\tryFOUR\lib\site-packages\django\contrib\admin\sites.py" in login 
    361.    self.each_context(request), 

File "C:\Users\Adila\Envs\tryFOUR\lib\site-packages\django\contrib\admin\sites.py" in each_context 
    284.    'available_apps': self.get_app_list(request), 

File "C:\Users\Adila\Envs\tryFOUR\lib\site-packages\django\contrib\admin\sites.py" in get_app_list 
    451.   app_dict = self._build_app_dict(request) 

File "C:\Users\Adila\Envs\tryFOUR\lib\site-packages\django\contrib\admin\sites.py" in _build_app_dict 
    397.    has_module_perms = model_admin.has_module_permission(request) 

File "C:\Users\Adila\Envs\tryFOUR\lib\site-packages\django\contrib\admin\options.py" in has_module_permission 
    476.   return request.user.has_module_perms(self.opts.app_label) 

File "C:\Users\Adila\Envs\tryFOUR\lib\site-packages\django\contrib\auth\models.py" in has_module_perms 
    438.   return _user_has_module_perms(self, module) 

File "C:\Users\Adila\Envs\tryFOUR\lib\site-packages\django\contrib\auth\models.py" in _user_has_module_perms 
    199.  for backend in auth.get_backends(): 

File "C:\Users\Adila\Envs\tryFOUR\lib\site-packages\django\contrib\auth\__init__.py" in get_backends 
    38.  return _get_backends(return_tuples=False) 

File "C:\Users\Adila\Envs\tryFOUR\lib\site-packages\django\contrib\auth\__init__.py" in _get_backends 
    27.   backend = load_backend(backend_path) 

File "C:\Users\Adila\Envs\tryFOUR\lib\site-packages\django\contrib\auth\__init__.py" in load_backend 
    21.  return import_string(path)() 

File "C:\Users\Adila\Envs\tryFOUR\lib\site-packages\django\utils\module_loading.py" in import_string 
    15.   module_path, class_name = dotted_path.rsplit('.', 1) 

Exception Type: AttributeError at /admin/login/ 
Exception Value: 'tuple' object has no attribute 'rsplit' 

そして、このエラーが発生すると、私はそれを修正する方法を正確に知っていない理由を私は知りません。私はコマンドを実行しようとすると、このエラーとそのほとんどを検索します。エラーはカンマによって引き起こされ、ここで閉じた括弧の後ろのコンマは削除されました:

STATICFILES_DIRS= (
     os.path.join(os.path.dirname(BASE_DIR), "static", "static") 
     ) 

私の管理ページにはまだアクセスできません。

私はトレースバックに従った:

def import_string(dotted_path): 
    """ 
    Import a dotted module path and return the attribute/class designated by the 
    last name in the path. Raise ImportError if the import failed. 
    """ 
    try: 
     module_path, class_name = dotted_path.rsplit('.', 1) 
    except ValueError: 
     msg = "%s doesn't look like a module path" % dotted_path 
     six.reraise(ImportError, ImportError(msg), sys.exc_info()[2]) 

    module = import_module(module_path) 

私は、ユーザーとスーパーユーザーのための独自のカスタム登録ページを作ってみます。

のinitの.py:

def load_backend(path): 
    return import_string(path)() 


def _get_backends(return_tuples=False): 
    backends = [] 
    for backend_path in settings.AUTHENTICATION_BACKENDS: 
     backend = load_backend(backend_path) 
     backends.append((backend, backend_path) if return_tuples else backend) 
    if not backends: 
     raise ImproperlyConfigured(
      'No authentication backends have been defined. Does ' 
      'AUTHENTICATION_BACKENDS contain anything?' 
     ) 
    return backends 


def get_backends(): 
    return _get_backends(return_tuples=False) 
+0

'dotted_pa​​th'は' string'とみなされ、 'tuple'を渡しました。 –

+0

あなたはもっと説明できますか?私はちょっと新鮮なdjangoです。私は非常に残念です@ MD.KhairulBasar – nuradilla

+0

あなたは 'import_string()'をどこで呼び出すのですか? –

答えて

0

あなたSTATICFILES_DIRSが間違っているように私には見えます。その例外が来ているところ

STATICFILES_DIRS = [ 
    os.path.join(os.path.dirname(BASE_DIR), "static", "static") 
] 

それは、何のスタックトレースがないため、原因が何であるかを診断するのは難しいが、そうでなければ、正確に見つけることができる:あなたはドキュメントを参照している場合https://docs.djangoproject.com/en/1.11/ref/settings/#staticfiles-dirs、それはあなたがリストとしてごSTATICFILES_DIRSを定義する必要があることを示しから。私はそれがこの設定に関連していると思う。

また、カンマなしでタプルを使用すると、式のように評価されます。あなたはカンマで同じことを行う場合のに対し

a = (
    'I think this is a tuple' 
) 
assert isinstance(a, tuple), "This is not a tuple" 

Traceback (most recent call last):
  File " <stdin> ", line 1, in <module>
AssertionError: This is not a tuple

a = (
    'I know this is a tuple', 
) 
assert isinstance(a, tuple), "This is not a tuple" 

あなたは、この第二の例には、このようなAssertionErrorがを取得していないだろう、私は例をあげます。

関連する問題