- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我是 django 的新手,两周以来一直在努力实现身份验证。
当我从我的 /auth/login
页面成功登录时,我想被重定向到 /auth/logged_in
。但是,它会将我重定向到 /auth/login/auth/logged_in
。我无法弄清楚问题所在。以下是我认为您需要帮助我的文件。
"""
Django settings for authTest project.
For more information on this file, see
https://docs.djangoproject.com/en/1.6/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.6/ref/settings/
"""
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/
# 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',
'auth'
)
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 = 'authTest.urls'
WSGI_APPLICATION = 'authTest.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.6/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.6/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.6/howto/static-files/
STATIC_URL = '/static/'
TEMPLATE_DIRS = (
'auth/templates'
)
# url to redirect after successfull login
LOGIN_REDIRECT_URL = 'auth/logged_in'
LOGIN_URL='/auth/login/'
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^auth/', include('auth.urls')),
)
from django.conf.urls import patterns, include, url
urlpatterns = patterns('',
url(r'^$', 'auth.views.index'),
url(r'^logged_in/$', 'auth.views.logged_in'),
url(r'^login/$', 'django.contrib.auth.views.login', {'template_name': 'login.html', 'redirect_field_name': '/auth/logged_in'}),
url(r'^logout/$', 'django.contrib.auth.views.logout', {'template_name': 'logout.html'}),
)
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response
from django.contrib.auth.decorators import login_required
from django.template import RequestContext
def index(request):
return HttpResponseRedirect('/login')
@login_required
def logged_in(request):
return render_to_response('logged_in.html',
context_instance=RequestContext(request)
)
{% extends "base.html" %}
{% block content %}
{% if form.errors %}
<p>Your username and password didn't match. Please try again.</p>
{% endif %}
<form method="post" action="{% url 'django.contrib.auth.views.login' %}">
{% csrf_token %}
<table>
<tr>
<td>{{ form.username.label_tag }}</td>
<td>{{ form.username }}</td>
</tr>
<tr>
<td>{{ form.password.label_tag }}</td>
<td>{{ form.password }}</td>
</tr>
</table>
<input type="submit" value="login" />
<input type="hidden" name="next" value="{{ next }}" />
</form>
{% endblock %}
提前致谢!
最佳答案
改变:
LOGIN_REDIRECT_URL = 'auth/logged_in'
到:
LOGIN_REDIRECT_URL = '/auth/logged_in'
您正在重定向到附加到当前 url 的路径。您需要使用前导斜杠重定向到附加到域根的路径。
关于python - 登录后重定向只需附加 LOGIN_REDIRECT_URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23772001/
我有一个只是 HTML 页面的应用程序。这会从另一台服务器调用 API 来获取/发送数据。这是我的问题。 我们如何维护登录用户的 session ?那就是,怎样才能阻止他在不登录的情况下访问其他页面进
这个问题在这里已经有了答案: Margin on child element moves parent element (18 个答案) 关闭 6 年前。 好吧,现在我遇到了这个问题,我只想调整“c
话说人生苦短,我用Python。 如果学python不是为了下载这些视频,那将毫无意义! 啊呸,老色批 咳咳,我们开始正题。 一、事前前奏 首先没装Python、pycharm的铁子先自己安装一下,我
问题陈述: 给定两张图像,例如下面布拉德·皮特的两张图像,请判断图像中是否包含同一个人。困难在于,我们每个人只有一张引用图像,并且如何确定任何其他传入图像是否包含同一个人或没有。 一些研究: 有几种不
我们的新闻源遇到了问题 - 它本质上是一个 Likebox 插件,可以节省更新网站和 Facebook 页面的麻烦。 Facebook 页面使用 iframe 填充新闻源。如果网站的浏览者未登录 Fa
任何人都可以给我一些关于如何使 javascript 计数计时器在 5 分钟后停止的小提示,我尝试过的代码低于我使用的代码,但我只想只用 5 分钟它在 5 分钟后停止。 var sec =
有没有办法为某些内容增加 View 表,或者如果不存在,则添加第一个 View 而不运行 2 个查询。这是我当前有效的代码。 function increment_views($id = null)
是否可以获取用户从天气应用程序中输入的位置(例如“马德里”)的 7 天天气预报,然后将其保存以供以后科学使用?在最好的情况下,我希望稍后有一个 if 语句,如下所示: #define sunny 1
根据外媒 9to5google 的消息,小米电视棒现已通过 FCC 的审批,可能很快在美国上市。 IT之家了解到,这款 FCC 认证的小米电视棒的型号为 MITVMDZ24AA,是两款小米 M
Visual Studio 2010 - 发布版 - 打开一个 xaml 文件大约需要 5 秒钟。 它在某些机器上执行,而不是所有机器! .cs 文件立即打开。它只发生在 XAML 上。 我们尝试了以
我正在解决“HackerRank”页面上的一个问题,特别是名为“追加和删除”的问题,但我无法使所有情况都正确。 https://www.hackerrank.com/challenges/append
我正在尝试从头开始构建幻灯片放映。我只想使用 javascript,而不使用 jquery。 到目前为止,当我单击“上一页”按钮时,它只会向左 move 50px 一次。如何让它每次单击“上一个”按钮
我有一个 Ionic 应用程序,我希望它连接到我的套接字。这在 SignalR 预览中工作得很好,它基本上仍然有效,但由于某种原因需要 2 分钟才能连接...... 连接时我也遇到一些错误: 这是我的
我对 Silverlight 和 MVVM/Prism 模式相当陌生,所以这可能是一个愚蠢的问题。 我有一个 View ,其中包含自定义控件。这些自定义控件实际上也是 View ,并且有 ViewMo
我在 python 上使用一些 DataFrame,我遇到了一种情况,我必须在相同的 if 条件下同时更改 2 列。我解决了我的问题,但我并没有只用一个 if 条件。 我试图搜索一些相关内容,但我只在
为什么scanf()在读取double时需要“%lf”中的l ,当 printf() 可以使用“%f”时,无论其参数是 double 还是 float ? 示例代码: double d; scanf(
为什么scanf()在读取double时需要“%lf”中的l ,当 printf() 可以使用“%f”时,无论其参数是 double 还是 float ? 示例代码: double d; scanf(
我是一名优秀的程序员,十分优秀!