Html表单和Django登录系统

时间:2017-06-16 06:06:20

标签: python html django forms

我想用Django制作简单的登录系统。我希望在提交表单后将用户发送到名为127.0.0.1:8000/login的页面。从那时起,我想获得随请求发送的帖子数据,检查如果用户存在于日期库中并且如果他登录则返回html页面或者如果用户尚未登录则返回其他html页面。问题是当我单击表单的提交按钮时,它不会向/ login请求。它停留在同一页面。任何帮助?

<!DOCTYPE html>
<html>
<body
<form action="/login/" method = "POST">
<input type="text" name="name"><br> 
 <input type = "submit" value = "Submit">
</form>
</body>
</html>

Urls.py:

from django.conf.urls import url
from django.contrib import admin
from simple import views as f
urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^form/$', f.form), 
    url(r'^login/$', f.data)

]

Views.py

  from django.shortcuts import render,render_to_response
  from django.http import HttpResponse
  from django.template import Context, loader

  def form(request):
     return render(request,"doccument.html")
  def data(request):
     name = request.POST.get('name')
     return HttpResponse(name)

1 个答案:

答案 0 :(得分:1)

在您的表单中,method应位于quotes

<form action="/login/" method="POST">