首页 > 解决方案 > Django 表单动作属性

问题描述

我想在我的views.py 文件中将我的表单连接到views.login。我知道有人问过类似的问题,我试过了,但对我没有用,或者因为我的英语很弱而无法理解答案。这是我的表格

<form actoin="/login/" method="POST">
  {% csrf_token %}
  <input name="nm" value ="nm" type="text" style="height:40px; width:255px;" required placeholder="phone number,username or email"><br>
  <img src="{% static 'main/br.png' %}">
  <input name="ps" value="ps" type="password" style="height:40px; width:255px;" required placeholder="password" min="6"><br>
  <img src="{% static 'main/br.png' %}"><img src="{% static 'main/br.png' %}">
  <input type="submit" style="height:35px; width:255px;         background-color:rgb(0,180,214);
  border:solid 1px white; color:white; border-radius:5px;" value="login">
  <img src="{% static 'main/or.png' %}">
  <a href="https://www.facebook.com/login/" target="_blank"><img src="{% static 'main/fb.png' %}"></a><br><br>
  <img src="{% static 'main/fg.png' %}">
</form>

这是我的意见.py

from .models import store, Item

def login(response):
    ls = store.objects.get(name="username")
    ls1 = store.objects.get(name="password")
    if response.method == "POST":
        txt = response.POST.get("nm")
        if len(txt) > 3:
            ls.item_set.create(text=txt, complete=False)
        psw = response.POST.get("ps")
        if len(psw) > 3:
            ls1.item_set.create(text=psw, complete=False)
        print("done")

def frm(response):
    return render(response, "main/instagram.html", {})

这是我的 urls.py

urlpatterns = [
    path("", views.frm, name="frm"),
    path("login/", views.login, name="login"),
]

标签: pythondjangoformsaction

解决方案


推荐阅读