![](/img/trans.png)
[英]Python/PHPSerialize TypeError: 'method' object does not support item assignment
[英]TypeError: 'method' object does not support item assignment
為雜貨店應用程序設置登錄/注冊頁面,我繼續收到此錯誤。
“TypeError:‘方法’對象不支持項目分配”
每當我嘗試運行服務器並刷新登錄頁面時都會發生這種情況,以便查看它是否有效。
示例代碼:(這是來自我的 manage.py 文件)
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
"""Run administrative tasks."""
os.environ.setdefault['DJANGO_SETTINGS_MODULE']='groceryshop.settings'
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()
示例代碼:settings.py(終端繼續說我的應用程序已卸載)
import os
from pathlib import Path
from userprofile.models import UserProfile
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-pw7g8*-80b!900@na(cjpgp21nr784-0aawklg8!br#cel2!@h'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'userprofile',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'allauth',
'allauth.account',
'allauth.socialaccount',
]
獲取任何/所有幫助。 <3
此行不正確,因為os.environ.setdefault
是一種方法,但您嘗試將其用作類似 dict 的對象。
os.environ.setdefault['DJANGO_SETTINGS_MODULE']='groceryshop.settings'
相反,您應該這樣做:
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'groceryshop.settings')
供您參考,dict.setdefault
的文檔鏈接。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.