장고에서 login_required 데코레이션을 얻으려고합니다.Django login_required - 사용자가 이미 이미 인증했습니다.
내보기, 똑바로 나를 수 있습니다이
@login_required
def index(request):
if request.user.is_authenticated():
print 'in'
else:
print 'out'
context = {'test_obj': 'Testing Testing 123'}
return render(request, 'web_copo/index.html', context)
이
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
TEMPLATE_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',
'web_co',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = 'project_copo.urls'
WSGI_APPLICATION = 'project_copo.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.7/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'co_db',
'USER': 'root',
'PASSWORD': 'xxx',
'Host': '127.0.0.1',
'Port': '',
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.7/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.7/howto/static-files/
TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates')]
STATIC_URL = '/static/'
TEMPLATE_CONTEXT_PROCESSORS = ("django.contrib.auth.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.core.context_processors.static",
"django.core.context_processors.tz",
"django.contrib.messages.context_processors.messages",
'django.core.context_processors.csrf',
내가 페이지를 탐색 할 때마다 같은 내 settings.py 것 같습니다. 또한 '에서'인쇄 django는 내 사용자가 이미 로그인되었다고 생각합니다. 로그인하지 않았으므로 왜 이런 일이 일어나지 않습니다. 내가 도대체 뭘 잘못하고있는 겁니까?
감사합니다.
'request.user'를 인쇄 해보십시오. – kviktor
ok ... 내 유일한 사용자이고 수퍼 유저 인 'root'에 로그인했습니다. 왜 자동으로 루트에 로그인 했습니까?이 동작을 어떻게 비활성화합니까? – shaw2thefloor
기본적으로 루트로 '로그인하지 않습니다 ... 어쩌면 전에 로깅을하고 같은 사용자를 얻을 수 있습니다. 로그인을 시도하거나 크롬 incog 모드에서 실행하여이를 방지하십시오. – cdvv7788