【发布时间】:2019-01-10 01:42:08
【问题描述】:
我有登录 html 页面和索引 html 页面,但是当我写下用户名和密码时,页面只刷新而不做任何事情。 我使用 Django 2.x 和 Python 3.4
登录html中的代码:
<form class="form-signin" action='{% url 'myapp:index' %}' method="post">
{% csrf_token %}
<img class="mb-4" src='{% static 'app/img/logo.png' %}' alt="" width="300" height="100">
<h1 class="h3 mb-3 font-weight-normal">mysite</h1>
<br>
<div class="group">
<input type="username" id="inputUser" name="username" class="form-control" placeholder="Username" required autofocus alt="" width="300" height="100">
</div>
<div class="group">
<input type="password" id="inputPassword" name="password" class="form-control" placeholder="Password" required alt="" width="300" height="100">
</div>
<div>
<button class="btn btn-lg btn-primary btn-block" type="submit">Accedi</button>
</div>
</form>
这是我的观点:
def index(request):
username = request.post["username"]
password = request.post["password"]
user = authenticate(request, username=username, password=password)
if user is not None:
login(request, user)
return render(request, "myapp/index.html")
我做错了什么? 谢谢
编辑:
我的错误日志
AH00558:httpd.exe:无法可靠地确定服务器的完全限定域名,使用 fe80::1c06:8ac5:1b1e:aa2f。全局设置“ServerName”指令以禁止显示此消息 [Thu Aug 02 12:35:17.911829 2018] [mpm_winnt:notice] [pid 4196:tid 452] AH00455: Apache/2.4.34 (Win64) mod_wsgi/4.6.4 Python/3.6 已配置——恢复正常操作 [2018 年 8 月 2 日星期四 12:35:17.912829] [mpm_winnt:notice] [pid 4196:tid 452] AH00456:Apache Lounge VC15 服务器建成时间:2018 年 7 月 11 日 13:09:01 [Thu Aug 02 12:35:17.912829 2018] [core:notice] [pid 4196:tid 452] AH00094:命令行:'c:\Apache\bin\httpd.exe -d C:/Apache' [Thu Aug 02 12:35:17.913829 2018] [mpm_winnt:notice] [pid 4196:tid 452] AH00418: Parent: Created child process 2112 AH00558:httpd.exe:无法可靠地确定服务器的完全限定域名,使用 fe80::1c06:8ac5:1b1e:aa2f。全局设置“ServerName”指令以禁止显示此消息 AH00558:httpd.exe:无法可靠地确定服务器的完全限定域名,使用 fe80::1c06:8ac5:1b1e:aa2f。全局设置“ServerName”指令以禁止显示此消息 [Thu Aug 02 12:35:18.335853 2018] [mpm_winnt:notice] [pid 2112:tid 472] AH00354: Child: 启动 64 个工作线程。
我的 access.log:
myip - - [02/Aug/2018:12:35:28 +0200] "GET /myapp/ HTTP/1.1" 200 2633 myip - - [02/Aug/2018:12:35:48 +0200] "POST /myapp/ HTTP/1.1" 200 2633
编辑2: 我将 url.py 从路径更改为 url 并解决了问题...现在页面加载正确,感谢大家
【问题讨论】:
-
您的预期行为是什么?
-
我希望当我点击“Accedi”时,程序会验证用户是否存在于数据库中,如果存在,则加载索引页面
-
您的服务器跟踪日志中有任何消息吗?
-
我在帖子中添加了日志
标签: django python-3.x