沐风林 2019-07-10 23:21 采纳率: 0%
浏览 774

Django2.0中form表单提交跳转到另一个界面目录重复导致404?

1.写了个简单的from表单登陆跳转,提交之后登陆页面的路径重复报错404,

1.1)urls:

from django.contrib import admin
from django.urls import path ,re_path
from app01 import views


urlpatterns = [
    path('admin/', admin.site.urls),
    re_path('^login.html/$',views.login),
    re_path('^indexUser.html/$',views.index),
]

1.2)views代码:

def login(req):
    message=''
    print('userName',req.method)
    print('url'+req.path)
    # if req.method == "POST":
    #     userName = req.POST.get("userName")
    #     pwd = req.POST.get("pwd")
    #     if userName=='mufenglin' and pwd =='mufenglin':
    #         res = redirect('/index.html')
    #         res.set_cookie('userName',userName)
    #         return res
    #     else:
    #         message='用户名或者密码错误'
    return render(req,"login.html",{'message':message})


def index(req):
   #如果用户已经登陆,获取用户名
   #否则返回登陆页面

   print(req.COOKIES.get("userName"))
   if req.COOKIES.get("csrf_token"):
       userName = 'gongsunyang'
       return render(req,"indexUser.html",{'userName':userName})
   else:
       return redirect("/login.html")

1.3form表单

<!DOCTYPE HTML>
<html>
<head>
<title>Home</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
    <form action="login.html" method="post">
            {% csrf_token %}
            <div>
                <label for="user">用户名:</label>
                <input id ="user" type="text" name="userName"/>
            </div>
            <div>
                <label for="password">密码: </label>
                <input id="pwd" type="password" name="pwd"/>
            </div>
            <div>
                <input type="submit" value="登陆"/>
                <span style="color:#ffd155;">{{ message }}</span>
            </div>
    </form>
</body>
</html>

2.操作步骤:
图片说明

3.报错截图
图片说明

  • 写回答

1条回答 默认 最新

  • 战渣渣 2019-07-11 09:29
    关注

    你的报错截图没有贴出来呢。

    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料