[英]django registration redux not redirecting to base.html after login
I am working on a e-comm application, I am using django registration redux to setup user registration and login. 我正在开发一个e-comm应用程序,我正在使用django registration redux来设置用户注册和登录。 Initially when I set up the register/login system it was working fine..when I put bootstrap and styles in my base.html, the functionality broke and after user login rather it redirecting to base.html..it tries to fetch http://localhost:8000/accounts/login/ , this url..
最初,当我设置注册/登录系统时,它工作正常..当我在我的base.html中放置bootstrap和样式时,功能破坏并且在用户登录之后而不是重定向到base.html ..尝试获取http: // localhost:8000 / accounts / login / ,这个网址..
I can't seem to figure out the reason. 我似乎无法弄清楚原因。
Here is my settings.py Also to note, when I put 'store' at the last in Installed apps section and try to click login/register url comes back to base.html rather than login/register pages. 这是我的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 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 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')),
]
To redirect to base.html you have to make a little change in setting.py 要重定向到base.html,您必须在setting.py中进行一些更改
just add LOGIN_REDIRECT_URL = 'base_url' 只需添加LOGIN_REDIRECT_URL ='base_url'
Hope it works 希望它有效
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.