I've done a simple login that works fine while the authenticated user is redirected to a page with url:
我做了一个简单的登录,当认证的用户被重定向到一个具有url的页面时,可以正常工作:
url(r'^(?P<user_id>\d+)/$', 'auth.views.main', name='main'),
Now I'm trying to use a LoginRequired-Middleware
but when I do and I try to login I get:
现在我正在尝试使用LoginRequired-Middleware,但是当我这么做并试图登录时,我得到了:
"POST /login/ HTTP/1.1" 302 0
"GET /1000/ HTTP/1.1" 302 0
and I remain to the initial login-page. I use a common snippet for doing that with
我仍然停留在初始登录页面。我使用一个通用的代码片段来实现这一点
LOGIN_URL = ( '/login/' )
LOGIN_URL = ('/login/')
What's going wrong?
什么错了吗?
1
Unfortunately your provided code is insufficient to determine your error, so I can only give you pointers:
不幸的是你提供的代码不足以确定你的错误,所以我只能给你一些建议:
Make sure you aren't actually still caching an HTTP 302 REDIRECT site, from earlier experimenting. See here for useful hints.
Reset your browser-cache. If you are using Chrome, you can get several cache clearance options by pressing CTRL+SHIFT+J (starting the Developer Tools), and long pressing the Reload button next to the top navigation url-bar.
确保您实际上并没有缓存HTTP 302重定向站点,从早期的试验。请在这里查看有用的提示。重设你的浏览器缓存。如果你正在使用Chrome,你可以通过按CTRL+SHIFT+J(启动开发人员工具)和长按顶部导航栏旁边的Reload按钮获得几个缓存清除选项。
For Firefox, see also these useful suggestions.
对于Firefox,请参见这些有用的建议。
http://support.mozilla.org/es/questions/848678
http://support.mozilla.org/es/questions/848678
https://superuser.com/questions/23134/how-to-turn-off-firefox-cache
https://superuser.com/questions/23134/how-to-turn-off-firefox-cache
Did you just upgrade Django from version <1.3.x? I came across a situation where passwords were rewritten with a new default-Hasher, and thus one could no longer log in. Check password-hasher consistency directly in your database, within the auth_users
- table. For instance SHA1 password-hashes start with sha1...
您是否刚刚将Django从版本<1.3.x升级?我遇到过这样的情况:密码被重新写入一个新的默认密码,这样人们就不能再登录了。在auth_users - table中,直接在数据库中检查密码-hasher一致性。例如,SHA1密码哈希以SHA1开始……
Make sure to setup the list PASSWORD_HASHERS
in your settings.py
, is in an order that retains the original project's primary Hasher on top. i.e. the hashing-algorithm that was used to initially hash the user passwords.
确保在设置中设置PASSWORD_HASHERS列表。py的顺序保留了原始项目的主节点。即最初用来哈希用户密码的哈希算法。
Is the url(r'...'...)
in the root urls.py
of your project?
是根url中的url(r'…'…)。py你的项目吗?
Make sure 'django.contrib.auth'
is listed in your INSTALLED_APPS
section of settings.py
(though you should get error's if that is not the case) and apps that must be loaded beforehand, are actually placed uppermost.
确保“django.contrib。auth'在您的INSTALLED_APPS设置部分中列出。py(如果不是这样的话,您应该得到error)和应用程序,这些应用程序必须事先加载,实际上是放在最上面的。
Check the setup of your TEMPLATE_CONTEXT_PROCESSORS
, MIDDLEWARE_CLASSES
in settings.py according to your snippet's comments and make sure it is compatible with the SessionMiddleware
of your Django version.
在设置中检查template_context_processor、MIDDLEWARE_CLASSES的设置。根据您的代码片段的注释,并确保它与Django版本的SessionMiddleware兼容。
Check all codelines in your project that make redirects:
检查项目中所有重定向的代码线:
Check for:
检查:
from django.views.generic.base import RedirectView
url(r'^.*$', RedirectView.as_view(url='<url_to_view>', permanent=False), name='index')
or
或
from django.http import HttpResponsePermanentRedirect
HttpResponsePermanentRedirect('url...')
Note that in Django 1.5 the deprecated redirect_to
function has been replaced by RedirectView
, according to their generic view paradigm.
注意,在Django 1.5中,弃用的redirect_to函数已经被RedirectView取代,这是根据它们的通用视图范式。
重定向(…)
url('^pattern/$', lambda _: redirect('/redirecttourl/'))
url(r'^pattern$', redirect('example.com')),
url(r'^pattern$', redirect(projectname.views.home)),
(r'^accounts/profile/$', 'redirect_to', {'url': 'generic_account_url'}),
HttpResponseRedirect(....)
HttpResponseRedirect(request.META.get('HTTP_REFERER','/'))
next
query string. next=
determines the the page to return to after login:See: http://docs.djangoproject.com/en/dev/topics/auth/#django.contrib.auth.decorators.login_required
见:http://docs.djangoproject.com/en/dev/topics/auth/ django.contrib.auth.decorators.login_required
It helps providing the entire HTTP access history during the login process. As you do not hang in an redirect-loop, more HTTP's than the two mentioned must follow.
它有助于在登录过程中提供整个HTTP访问历史记录。由于不挂在redirect循环中,因此必须遵循比前面提到的两个HTTP更多的HTTP。
本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2012/08/06/6f8a9f7d64a43d1dad4ba407a584d46f.html。