"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. 036--MySQL扩展

    一.视图 视图是一个虚拟表(非真实存在),其本质是[根据SQL语句获取动态的数据集,并为其命名],用户使用时只需使用[名称]即可获取结果集,并可以将其当作表来使用. SELECT * FROM ( S ...

  2. 任务17:从UML角度来理解依赖

    什么是依赖 如果我们用EF操作数据库. 那么CustomerController就对Context形成了依赖. 我们这种依赖的写法就是隐式的依赖 显式依赖于隐式依赖 怎么理解隐式的依赖呢? 三层架构是 ...

  3. bzoj 4446: [Scoi2015]小凸玩密室【树形dp】

    神仙题!参考https://www.cnblogs.com/wfj2048/p/7695711.html 注意完全二叉树不是满二叉树!!!! 设g[u][j]为u遍历完子树到深度为i-1的祖先的兄弟的 ...

  4. IT兄弟连 JavaWeb教程 请求重定向案例

    Check2Servlet类与Output2Servlet类之间为请求转发关系.在web.xml文件中,为Check2Servlet映射的URL为"/check2",为Output ...

  5. 如何用Python在10分钟内建立一个预测模型

    转载自:https://baijia.baidu.com/s?old_id=307995 最近,我从孙子(指<孙子兵法>——译者注)那里学到了一些策略:速度和准备 “兵之情主速,乘人之不及 ...

  6. Java对象的内存布局以及对象的访问定位

    一 Java对象的内存布局 在HotSpot虚拟机中,对象在内存中的布局分为3个区域 对象头(Header) Mark Word(在32bit和64bit虚拟机上长度分别为32bit和64bit)存储 ...

  7. Centos 6.5安装MySQL-Python遇到的问题--解决办法一

    系统:CentOS release 6.5 (Final) MySQL版本:mysql  Ver 14.14 Distrib 5.7.19, for Linux (x86_64) using  Edi ...

  8. 机器学习概念之特征处理(Feature processing)

    不多说,直接上干货! 肯定也有不少博友,跟我一样,刚开始接触的时候,会对这三个概念混淆. 以下是,特征处理.特征提取.特征转换和特征选择的区别! 特征处理主要包含三个方面:特征提取.特征转换和特征选择 ...

  9. discuz x2.5用户注册后邮箱认证后无法收到邮件或者直接进垃圾箱

    又是一个周末,jquery特效继续折腾我那discuz论坛,我开启了个邮箱验证,恶意注册的太恶心了,没有办法. 能稍微屏蔽点,但是问题来了,据亲们反应,无法收到验证邮件,或者有时间直接进入垃圾箱,这个 ...

  10. vue_resource 使用说明

    前几天用vue-resource调用接口,用post方式给后端,发现后端php接受不到数据,这好奇怪,最后发现提交给后端的时候 需要加一个参数 就是:emulateJSON : true 这句话的意思 ...