[英]django registration redux not redirecting to base.html after login
我正在開發一個e-comm應用程序,我正在使用django registration redux來設置用戶注冊和登錄。 最初,當我設置注冊/登錄系統時,它工作正常..當我在我的base.html中放置bootstrap和樣式時,功能破壞並且在用戶登錄之后而不是重定向到base.html ..嘗試獲取http: // localhost:8000 / accounts / login / ,這個網址..
我似乎無法弄清楚原因。
這是我的settings.py另外需要注意的是,當我在“已安裝的應用程序”部分的最后一個“存儲”並嘗試單擊“登錄/注冊”時,url將返回base.html而不是登錄/注冊頁面。
“””
Django settings for bookstore project.
Generated by 'django-admin startproject' using Django 1.8.
For more information on this file, see
https://docs.djangoproject.com/en/1.8/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.8/ref/settings/
"""
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
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: 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',
'bootstrap3',
'bootstrap_themes',
)
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_URL = "/store/"
base.html文件
{% extends 'bootstrap3/bootstrap3.html' %}
{% load staticfiles %}
{% load bootstrap3 %}
{% load bootstrap_themes %}
{% bootstrap_styles theme='simplex' type='min.css' %}
{% block bootstrap3_extra_head %}
<link href = "http://fonts.googleapis.com/css?family=Open+Sans:400,300,700" rel = "stylesheet" type="text/css"/>
<link href = "{% static 'base/css/style.css' %}" rel = "stylesheet" type="text/css"/>
{% endblock %}
{% block bootstrap3_title %}
{% block title %}
Welcome to Pick A Book !!
{% endblock %}
{% endblock %}
{% block bootstrap3_content %}
<nav class = "navbar navbar-inverse navbar-fixed-top">
<div class = "container">
<div class = "navbar-header">
<button type="button" class ="navbar-toggle" data-toggle="collapse" data-target = "#navbar">
<span class = "icon-bar"> </span>
<span class = "icon-bar"> </span>
<span class = "icon-bar"> </span>
</button>
<a href="{% url 'index' %}" class="navbar-brand">Pick A Book </a>
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="hvr-curl-top-right"><a href="{% url 'index' %}">Home</a></li>
<li class="hvr-curl-top-right"><a href="#about">About</a></li>
<li class="hvr-curl-top-right"><a href="#contact">Contact</a></li>
</ul>
<div class="navbar-form pull-right">
{% if request.user.is_authenticated %}
Welcome, {% if request.user.first_name %}
{{ request.user.first_name}}
{% else %}
{{ request.user.username }}
{% endif %}! <a href="(% url 'auth_logout' %}"> Log Out</a>
{% else %}
Welcome, mysterious person! <a href="{% url 'auth_login' %}">Log In? </a> or <a href="{% url 'registration_register' %}">Register</a>
{% endif %}
</div>
</div>
</div>
</nav>
<div class="container-fluid">
<img src="{% static 'base/img/header_full.jpg' %}" class ="bg">
<div class="parallax">
<div class="row">
{% block body %}
<div class="col-md-8 col-md-offset-2 col-sm-12 maincontent">
Welcome to our store!
</div>
{% endblock %}
</div>
</div>
</div>
<div class="row text-center navbar footer">
<div class="col-md-12">
<p> 2017 Pick A Book. Developed by <a href="http://kshitijrangai.com"> Kshitij Rangari </a> </p>
</div>
</div>
{% endblock %}
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')),
]
要重定向到base.html,您必須在setting.py中進行一些更改
只需添加LOGIN_REDIRECT_URL ='base_url'
希望它有效
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.