"GET /?next=/%3Fnext%3D/%253Fnext%253D/ HTTP/1.1" 302 0

solution reference

from django.contrib.auth.decorators import login_required

@login_required
def my_view(request):
...

@login_required官网解释:If the user isn’t logged in, redirect to settings.LOGIN_URL, passing the current absolute path in the query string

即将settings.LOGIN_URL设置为你的登陆页面地址

对于我的情况如下:

settings.py

LOGIN_URL = "/login/"

urls.py

url(r'^$', views.index, name="index"),
url(r'^login/$', views.user_login, name="login"),

views.py

@login_required
def index(request):
return render(request, "index1.html") def user_login(request):
if request.method == "POST":
# try:
# m = models.UserProfile.objects.get(email=request.POST['username'])
# except Exception:
# print("username doesn't exist")
# return render(request, "login.html")
username = request.POST["username"]
password = request.POST["password"]
user = authenticate(request, email=username, password=password)
error_msg = "账号或密码错误,请重新输入"
none_msg = "please input username and password"
if user is not None:
if user.is_active:
login(request, user)
# request.session['member_id'] = m.id
return redirect("/") # redirect to 127.0.0.1:8000/
else:
print(none_msg)
return render(request, "login.html", {"error_msg": none_msg})
else:
print(error_msg)
return render(request, "login.html", {"error_msg": error_msg})
else:
return render(request, "login.html")

django 127.0.0.1 将您重定向的次数过多的更多相关文章

  1. localhost 将您重定向的次数过多

    localhost 将您重定向的次数过多 问题描述:在项目中,出现 localhost 将您重定向的次数过多 ,有可能是因为设置重定向的时候,自己重定向到自己,或者重定向成环,导致无限的重定向.检查重 ...

  2. MVC中使用Action全局过滤器出现:网页无法正常运作 将您重定向的次数过多。解决办法

    前言当我们访问某个网站的时候需要检测用户是否已经登录(通过Session是否为null),我们知道在WebForm中可以定义一个BasePage类让他继承System.Web.UI.Page,重写它的 ...

  3. weiwo.wxmmd.com将您重定向的次数过多。尝试清除 Cookie.

    折腾了很久,最后更换PHP版本解决了,我的项目用的tp3.1.2,出现上图问题时的php版本是7.1,换回5.6就没有这个问题.希望能为大家提供一个思路.

  4. Django使用本机IP无法访问,使用127.0.0.1能正常访问

    使用Django搭建web站点后,使用127.0.0.1能访问,但是用自己本机IP却无法访问. 我们先到Django项目中找到setting文件 找到——> ALLOWED_HOSTS = [] ...

  5. django 开发Broken pipe from ('127.0.0.1', 58078)问题解决

    最近写的一个项目,前端使用了表单submit提交,后端接收POST数据存储.实际上的逻辑并不复杂, django接收到的时候会产生Broken pipe from ('127.0.0.1', 5807 ...

  6. 前端ajax访问 django 报错 POST http://127.0.0.1:8001/xxx 403 (Forbidden)

    前端使用 ajax 访问后端 django 程序 报错误: POST http://127.0.0.1:8001/xxx 403 (Forbidden) 错误原因: 参数中未携带 csrfmiddle ...

  7. 学习django就看这本书了!django book 2.0中文版

    所属网站分类: 资源下载 > python电子书 作者:熊猫烧香 链接:http://www.pythonheidong.com/blog/article/29/ 来源:python黑洞网 dj ...

  8. eclipse里启动tomcat无法通过127.0.0.1访问

    在eclipse里面添加tomcat,再发布一个web项目进去,然后启动tomcat,日志显示tomcat在eclipse里面正常启动,hosts里面配置了ip跟域名的对应关系. 通过域名访问可以正常 ...

  9. python2 + selenium + eclipse 中,配置好runserver 127.0.0.1:9000,运行的时候,报错

    python2 + selenium + eclipse 中,配置好runserver 127.0.0.1:9000,运行的时候,报错,如图: 原因:       google发现是WSGI appl ...

随机推荐

  1. E - Alice and Bob

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  2. zabbix 监控mysql状态 -Windows

    由于公司爬虫mysql数据库在Windows下面,监控一下: 主要命令:mysqladmin -uroot -proot -h127.0.0.1 ping 2>D:\zabbix\waring. ...

  3. clipse maven 项目 出现红色叹号 解决方法

    感叹号代表jar包不全,看你是maven工程,pom.xml报错,应该是jar包路径不对.打开pom.xml文件,查看报错位置和报错信息. 缺失的jar包的配置去http://search.maven ...

  4. 土法搞docker系列之自制docker的graph driver vdisk

    写在最前 偶然整理,翻出来14年刚开始学docker的时候的好多资料.当时docker刚刚进入国内,还有很多的问题.当时我们的思考方式很简单,docker确实是个好的工具,虽然还不成熟.但是不能因为短 ...

  5. python __builtins__ memoryview类 (46)

    46.'memoryview',  返回给定参数的内存查看对象(Momory view).所谓内存查看对象,是指对支持缓冲区协议的数据进行包装,在不需要复制对象基础上允许Python代码访问. cla ...

  6. Jquery禁用网页右键菜单

    $(function(){ $(document).bind("contextmenu",function(e){ return false; }); });

  7. 鸟哥私房菜基础篇:学习 Shell Scripts习题

    猫宁!!! 参考链接:http://cn.linux.vbird.org/linux_basic/0340bashshell-scripts.php 鸟哥是为中国信息技术发展做出巨大贡献的人. 1-请 ...

  8. CF580D Kefa and Dishes 【状压dp】By cellur925

    题目传送门 友情链接:new2zydalao%%%  一篇优秀的状压文章 题目大意:$n$个菜有$k$个规则,如果kefa在吃完第$xi$个菜之后吃了第$yi$个菜(保证$xi$.$yi$不相等), ...

  9. 跟我一起玩Win32开发(16):ListView的多个视图

    在上一个例子中,我们只用到了ListView的Report视图,也就是详细视图.本文我们再把上一篇文章中所用的例子进行一下扩展,例子源码可以到俺的资源区下载. 我们为ListView中显示的数据加上图 ...

  10. Fast Bit Calculations LightOJ - 1032

    Fast Bit Calculations LightOJ - 1032 题意:求0到n的所有数的二进制表示中,"11"的总数量.(如果有连续的n(n>2)个1,记(n-1) ...