我目前無法獲得@login_required
重定向的next
值,原因有很多。我重視我的代碼爲login.html的頁面,我的項目設置@login_required得到下一個
輸入name=next
value=''
而它應該包含從{{ next }}
這是在調試轉儲顯示爲值:
GET data
Variable Value
u'next' [u'/accounts/profile/']
login.html
:
{% extends "base.html" %}
{% block content %}
{% if form.errors %}
<p class="error"> Sorry, you have entered an incorrect username or password</p>
{% endif %}
<form action="/accounts/auth/" method="post">{% csrf_token %}
<label for="username">User name:</label>
<input type="text" name="username" value="" id="username">
<label for="password">Password:</label>
<input type="password" name="password" value="" id="password">
<input type='text' name="next" value="{{ next }}">
<input type="submit" value="login">
</form>
{% endblock %}
settings
:
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# 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',
'debug_toolbar',
'userprofile',
)
MIDDLEWARE_CLASSES = (
'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 = 'django_yunite.urls'
WSGI_APPLICATION = 'django_yunite.wsgi.application'
# Internationalization
# https://docs.djangoproject.com/en/1.6/topics/i18n/
LANGUAGE_CODE = 'en-ca'
TIME_ZONE = 'EST'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.6/howto/static-files/
STATIC_URL = '/static/'
STATICFILES_DIRS = (
('assets', '/home/user/GitHub/venv_yunite/django_yunite/static/'),
)
TEMPLATE_DIRS = (
'./templates',
'/article/templates',
)
STATIC_ROOT = "/home/user/Documents/static/"
AUTH_PROFILE_MODULE = 'userprofile.UserProfile'
from django.conf import global_settings
TEMPLATE_CONTEXT_PROCESSORS = global_settings.TEMPLATE_CONTEXT_PROCESSORS + (
"django.core.context_processors.request",
)
views.py
:
def login(request):
c={}
c.update(csrf(request))
return render_to_response('login.html', c)
這是使用自己的登入查看這裏,或正在使用'django.contrib.auth.views.login'?如果前者,你是否將'next'參數傳遞給你的上下文? – jonafato
登錄視圖是我自己的,我將發佈代碼 –