2017-03-09 105 views
0

我正在尝试构建在线书店并使用django注册redux我已经构建了一个2路验证登录系统。用户登录后,我希望它重定向到主主页(在我的情况/ /商店),但由于某种原因它是指向帐户/配置文件,我不知道它从哪里获取此网址。Django登录后没有重定向到所需的网址

这里是我的Settings.py代码

import os 

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.8/howto/deployment/checklist/ 

# SECURITY WARNING: keep the secret key used in production secret! 
SECRET_KEY = '&icg8)16be&h!rw)6_#3#v!1dn5nx_*[email protected](88tw5z6$a' 

# 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', 
    'social.apps.django_app.default', 
    'store', 
    'registration', 
) 

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', 
    'django.middleware.security.SecurityMiddleware', 
) 

ROOT_URLCONF = 'bookstore.urls' 

TEMPLATES = [ 
    { 
     'BACKEND': 'django.template.backends.django.DjangoTemplates', 
     'DIRS': [], 
     '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', 
       'social.apps.django_app.context_processors.backends', 
       'social.apps.django_app.context_processors.login_redirect', 
      ], 
     }, 
    }, 
] 

WSGI_APPLICATION = 'bookstore.wsgi.application' 

AUTHENTICATION_BACKENDS = (
    'social.backends.facebook.FacebookOAuth2', 
    'django.contrib.auth.backends.ModelBackend' 
) 

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

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


# Internationalization 
# https://docs.djangoproject.com/en/1.8/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.8/howto/static-files/ 

STATIC_URL = '/static/' 


# Registration 

ACCOUNT_ACTIVATION_DAYS = 7 
REGISTRATION_AUTO_LOGIN = True 
LOGIN_REDIRECT_USER = "/store/" 

这是我的urls.py

from django.conf.urls import include, url 
from django.contrib import admin 

urlpatterns = [ 
    # Examples: 
    # url(r'^$', 'bookstore.views.home', name='home'), 
    # url(r'^blog/', include('blog.urls')), 
    url(r'^admin/', include(admin.site.urls)), 

    url (r'^store/', include('store.urls'), name='store'), 
    url(r'^accounts/', include('registration.backends.default.urls')), 
    url ('', include('social.apps.django_app.urls', namespace = 'social')), 

而且我的login.html

<form method = "post" action ="."> 
    {% csrf_token %} 
    {{ form.as_p }} 
    <input type = "submit" value="LogIn"/> 
    <input type = "hidden" name = "next" value = "{{next}}"/> 
</form> 

<a href = " {% url 'social:begin' 'facebook' %}"> Login With Facebook</a> 

一个帮助是极大的赞赏

+0

你能否分享你的'views.py'呢? –

+0

正常登录或通过Facebook登录错误? “/ store /”是否存在?或者它只是一个没有子网址的根作为'r“^ $”' –

回答

0

你已经使用了错误的设置名称。它应该是

LOGIN_REDIRECT_URL = "/store/" 

您有LOGIN_REDIRECT_USER

+0

* facepalm *我看了5行期望错误的那一行,但看不到它 –

+0

该死!非常感谢 !!错别字耗尽了我的大脑数小时...非常感谢:D –