2017-10-19 12 views
-2

안녕하세요 여러분, 장고에 오류가 있습니다. 정확히 어디에서 오류가 발생하는지 제발 제 코드를 살펴보고 해결하도록 도와주세요. 내 의견입니다. 이 appsuite 프로젝트 폴더/notes/index/context의 TypeError는 RequestContext가 아닌 dict이어야합니다.

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 


# Quick-start development settings - unsuitable for production 
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/ 

# SECURITY WARNING: keep the secret key used in production secret! 
SECRET_KEY = '&1hv71rr0e7b!m)7sv(p7of0p7q0%-mb9o*^r*amw$d1o3%=s_' 

# SECURITY WARNING: don't run with debug turned on in production! 
DEBUG = True 

ALLOWED_HOSTS = [] 


# Application definition 

INSTALLED_APPS = [ 
    'django.contrib.admin', 
    'django.contrib.auth', 
    'django.contrib.contenttypes', 
    'django.contrib.sessions', 
    'django.contrib.messages', 
    'django.contrib.staticfiles', 
] 

MIDDLEWARE = [ 
    'django.middleware.security.SecurityMiddleware', 
    'django.contrib.sessions.middleware.SessionMiddleware', 
    'django.middleware.common.CommonMiddleware', 
    'django.middleware.csrf.CsrfViewMiddleware', 
    'django.contrib.auth.middleware.AuthenticationMiddleware', 
    'django.contrib.messages.middleware.MessageMiddleware', 
    'django.middleware.clickjacking.XFrameOptionsMiddleware', 
] 

ROOT_URLCONF = 'appsuite.urls' 

WSGI_APPLICATION = 'appsuite.wsgi.application' 

TEMPLATES = [ 
    { 
     'BACKEND': 'django.template.backends.django.DjangoTemplates', 
     'DIRS': [os.path.join(BASE_DIR, 'notes/templates')], 

     'APP_DIRS': True, 
     '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', 

      ], 
     }, 
    }, 
] 



# Database 
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases 

DATABASES = { 
    'default': { 
     'ENGINE': 'django.db.backends.sqlite3', 
     'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 
    } 
} 


# Password validation 
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators 

AUTH_PASSWORD_VALIDATORS = [ 
    { 
     'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 
    }, 
    { 
     'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 
    }, 
    { 
     'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 
    }, 
    { 
     'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 
    }, 
] 


# Internationalization 
# https://docs.djangoproject.com/en/1.11/topics/i18n/ 

LANGUAGE_CODE = 'en-us' 

TIME_ZONE = 'UTC' 

USE_I18N = True 

USE_L10N = True 

USE_TZ = True 


# Static files (CSS, JavaScript, Images) 
# https://docs.djangoproject.com/en/1.11/howto/static-files/ 

STATIC_URL = '/static/' 

에서 내 settings.py 구성입니다

from django.shortcuts import render 
from django.http import HttpResponse 
from django.template import loader,RequestContext 

# Create your views here. 
def index(request): 
    template=loader.get_template("index.html") 
    rc=RequestContext(request,{'username':'hello'}) 
    return HttpResponse(template.render(rc)) 

메모 응용 프로그램에서 평 내 index.html을이

,974,377입니다3210

이 오류 스피 내가 페이지

TypeError at /notes/index/ 
context must be a dict rather than RequestContext. 
Request Method: GET 
Request URL: http://127.0.0.1:8000/notes/index/ 
Django Version: 1.11.6 
Exception Type: TypeError 
Exception Value:  
context must be a dict rather than RequestContext. 
Exception Location: C:\Users\madhumani\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\template\context.py in make_context, line 287 
Python Executable: C:\Users\madhumani\AppData\Local\Programs\Python\Python36-32\python.exe 
Python Version: 3.6.2 
Python Path:  
['D:\\python programs\\appsuite', 
'C:\\Users\\madhumani\\AppData\\Local\\Programs\\Python\\Python36-32\\python36.zip', 
'C:\\Users\\madhumani\\AppData\\Local\\Programs\\Python\\Python36-32\\DLLs', 
'C:\\Users\\madhumani\\AppData\\Local\\Programs\\Python\\Python36-32\\lib', 
'C:\\Users\\madhumani\\AppData\\Local\\Programs\\Python\\Python36-32', 
'C:\\Users\\madhumani\\AppData\\Local\\Programs\\Python\\Python36-32\\lib\\site-packages'] 
Server time: Thu, 19 Oct 2017 14:08:41 +0000 

를로드하려고하기 때 무엇이며,이 내 프로젝트가 얼마나입니다 :

appsuite(MAIN FOLDER) 
__db.sqlite3 
__manage.py 
__appsuite 
     __pycache__ 
     __init.py__ 
     __settings.py 
     __urls.py 
     __wsgi.py 
__notes 
     __pycache 
     __migrations 
     __templates 
      __index.html 
     __init.py 
     __admin.py 
     __apps.py 
     __models.py 
     __test.py 
     __urls.py 
     __views.py 

날이를 무엇인지 파악 도와주세요 솔루션 미리 감사드립니다.

+0

해당 오류 메시지에 대해 명확하지 않은 점은 무엇입니까? RequestContext를 사용하지 말고 dict를 사용하십시오. –

+0

@DanielRoseman이 답장을 보내 주셔서 감사합니다.하지만 정확히 무엇을 말하고 있는지 이해할 수 없으므로 이해해 주시길 바랍니다. 감사합니다. –

+0

나는 그것이 어떻게 불분명 할 수 있는지 이해할 수 없습니다. RequestContext를 사용하고 있습니다. 하지마. –

답변

0

오류 메시지에서 알 수 있듯이 RequestContext 대신 일반 사전을 사용해야합니다. 원래 코드는 RequestContext이므로 template.render()으로 전화하면 request을 인수로 전달할 수 있습니다.

def index(request): 
    template=loader.get_template("index.html") 
    context = {'username':'hello'} 
    return HttpResponse(template.render(context, request=request)) 

일반적으로 이와 같은 템플릿은 렌더링하지 않습니다. render 바로 가기를 사용하는 것이 훨씬 빠릅니다. 장고 1.8 내가 다른 튜토리얼 다음 추천 할 것입니다 2015 년 출시 된 이후로는, 그렇지 않으면 당신은 유사한 문제를 명중 할 수있다, 유효 기간이 지났 - 질문의 코드가 아주 오래된 것을

from django.shortcuts import render 

def index(request): 
    context = {'username':'hello'} 
    return render(request, 'index.html', context) 

참고.

+0

감사합니다. –