"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. LuoguP1370 Charlie的云笔记序列 【dp】By cellur925

    题目传送门 题目大意:给你一个序列,求出它所有区间的本质不同的子序列个数.(空序列也算作本质不同),数据范围$1e5$. 我们肯定是不能一个个枚举区间的...而且这个复杂度下,也就大概$O(n)$或$ ...

  2. ubuntu 给文件夹创建桌面快捷方式, 其实就是创建个软链接

    ln -s /home/zdj/Documents/windows_backup/2019Spring/ ~/Desktop/2019Spring ln -s /home/zdj/Documents/ ...

  3. Python之单元测试——HTMLTestRunner

    前置条件:把HTMLTestRunner.py文件拷贝到External Libraries—>site-packages里面 import unittestimport HTMLTestRun ...

  4. Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) B

    Description Bear Limak examines a social network. Its main functionality is that two members can bec ...

  5. UVa 11437 (梅涅劳斯定理) Triangle Fun

    题意: 给出三角形ABC顶点的坐标,DEF分别是三边的三等分点.求交点所形成的三角形PQR的面积. 分析: 根据梅涅劳斯定理,我们得到: ,解得 另外还有:,解得 所以AR : RP : PD = 3 ...

  6. angular 2 angular quick start Could not find HammerJS

    Angular2 的material中 引用了 hammerjs,遇到Could not find HammerJS错误,正确的步骤如下: 需要在如下位置增加 对material 和 hammerjs ...

  7. html5新增的主题结构元素

    article元素 article元素代表文档.页面或应用程序中独立的.完整的.可以独自被外部引用的内容. 它可以是一篇博客或者报刊中的文章,一篇论坛帖子.一段用户评论或独立的插件. 或其他任何独立的 ...

  8. vs 2015 编译cocos2dx 报错

    VS 2015 compiling cocos2d-x 3.3 error “fatal error C1189: #error: Macro definition of snprintf confl ...

  9. 编程挑战JavaScript进阶篇(慕课网题目)

    编程挑战 现在利用之前我们学过的JavaScript知识,实现选项卡切换的效果. 效果图: 文字素材: 房产: 275万购昌平邻铁三居 总价20万买一居    200万内购五环三居 140万安家东三环 ...

  10. Python学习日记之Python函数及方法使用总结

    1.  DocStrings 文档字符串     可以直接输出位于函数内定义的说明 # -*- coding:utf-8 -*- def printMax(x, y): '''示例: 说明文档''' ...