"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. linux中fork对打开文件的处理

    1 子进程复制父进程的数据段.BBS段.代码段.堆空间.栈空间和文件描述符 2 对于文件描述符采用共享的方式 后面这个例子可以清晰的看出 #include <sys/types.h> #i ...

  2. 博客使用的CSS代码备份

    CSS代码备份 /*simplememory*/ #google_ad_c1, #google_ad_c2 { display: none; } .syntaxhighlighter a, .synt ...

  3. java中多线程的两种创建方式

    一丶继承Thread类实现多线程 第一步:继承Thread类第二步:重写run()方法第三步:创建继承了Thread类的对象 , 调用start()方法启动. //线程创建方式一 : /* 第一步:继 ...

  4. Ubuntu开机之后报错结局方法

    sudo gedit /etc/default/apport 把里面的enabled=1改成enabled=,保存 201. 就是下雨也去.202. 我马上拿来.203. 孙英开飞机.204. 国华来 ...

  5. the little schemer 笔记(2)

    第二章 Do it, Do it Again, and Again, and Again... 假设l是 (Jack Sprat could eat no chicken fat) 那么 (lat? ...

  6. AtCoder Grand Contest 013 E - Placing Squares

    题目传送门:https://agc013.contest.atcoder.jp/tasks/agc013_e 题目大意: 给定一个长度为\(n\)的木板,木板上有\(m\)个标记点,距离木板左端点的距 ...

  7. AtCoder Beginner Contest 057 ABCD题

    A - Remaining Time Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Dol ...

  8. 递推DP URAL 1244 Gentlemen

    题目传送门 /* 题意:给出少了若干卡片后的总和,和原来所有卡片,问少了哪几张 DP:转化为少了的总和是否能有若干张卡片相加得到,dp[j+a[i]] += dp[j]; 记录一次路径,当第一次更新的 ...

  9. RHEL 6.5----CDN(lumanger)

    主机名  IP   服务 master 192.168.30.130  CDN(LuManager) slave 192.168.30.131  DNS  软件安装包下载地址及安装方法 http:// ...

  10. CentOS 安装图形化界面方法

    登录系统,使用yum 安装 #yum groupinstall 'X Window System'  -y 安装GNOME桌面环境 #yum groupinstall  'GNOME Desktop ...