沐风林 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
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog