Django 3 응용 프로그램에서 간단한 hello world 페이지를 만들고 있는데 오류가 발생합니다.
TypeError: 'module' object is not callable
여기에 오류가 있습니다.
TypeError at /
'module' object is not callable
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 3.0.11
Exception Type: TypeError
Exception Value:
'module' object is not callable
Exception Location: C:\Users\admin\AppData\Roaming\Python\Python37\site- packages\django\template\context.py in bind_template, line 246
Python Executable: C:\Program Files (x86)\Microsoft Visual
Studio\Shared\Python37_64\python.exe
Python Version: 3.7.8
Python Path:
['C:\\Users\\admin\\Repositories\\django-docker\\django-portal-base\\app',
'C:\\Program Files (x86)\\Microsoft Visual '
'Studio\\Shared\\Python37_64\\python37.zip',
'C:\\Program Files (x86)\\Microsoft Visual
Studio\\Shared\\Python37_64\\DLLs',
'C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\Python37_64\\lib',
'C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\Python37_64',
'C:\\Users\\admin\\AppData\\Roaming\\Python\\Python37\\site-packages',
'C:\\Program Files (x86)\\Microsoft Visual '
'Studio\\Shared\\Python37_64\\lib\\site-packages']
Server time: Thu, 14 Jan 2021 19:15:32 +0000
이전에는 작동했지만 지금은 갑자기 작동하지 않습니다. 여기, 내 것이요views.py
from django.shortcuts import render
# from django.http import HttpResponse
# from django.template import RequestContext, loader
# from django.template import Context
def index(request):
"""Placeholder index view"""
print('XXXX')
return render(request, 'hello_world/index.html')
#return HttpResponse('Hello, World!')
def test(request):
context = {'foo': 'bar'}
return render(request, 'hello_world/index.html', context)
오류가 줄에 return render(request, 'hello_world/index.html')
있지만 변경하면 return HttpResponse('Hello, World!')
제대로 작동합니다.
내 HTML 파일은 매우 간단합니다. index.html
<h3> MY DJANGO APP</h3>
html 파일도 올바른 폴더에 있습니다. templates/hello_world/index.html
설정
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': False,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'django.contrib.sessions'
],
},
},
]
django.contrib.sessions
호출 가능한 객체가 아니므로 유효한 컨텍스트 프로세서가 아닙니다.
실제로 앱이므로 INSTALLED_APPS
목록이 아니라 TEMPALTES
context_processors
목록 에 있어야 합니다. 거기에서 제거하면이 문제가 해결됩니다.
왜 이런 일이 발생합니까?
예외는 django/template/context.py
246 행 (Django v3.0.11)에서 발생한다고 언급합니다 . 246 번째 줄에 소스 코드가 보이면 이 줄에서 Django가 등록 된 템플릿 컨텍스트 프로세서를 실행하고 있음을 알 수 있습니다. , 이후 django.contrib.sessions
호출 가능한 객체하지만 모듈 아니다,이 예외 메시지가 나타납니다 'module' object is not callable
.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다