1. 登录功能的实现

1. form表单提交数据的注意事项:

1. 是form不是from,必须要有method和action
2. 所有获取用户输入的表单标签要放在form表单里面,表单标签必须要有name属性
3. form表单必须要有submit按钮

2. GET和POST

什么时候用GET:
向服务端请求一个网页的时候
搜索引擎检索时

什么时候用POST:
使用表单向服务器提交数据时

3. request.method --> 获取的是你请求的方法(GET/POST...) 必须是大写!!!
4. request.POST --> 获取POST提交过来的全部数据(字典)
5. redirect --> 跳转到指定页面!!!

基础必会三件套:

1. HttpResponse("OK")
2. render(request, "login.html")
3. redirect("URL")

  示例如下:

from django.conf.urls import url
from django.contrib import admin
from django.shortcuts import HttpResponse, render, redirect
from app01 import views

def index(request):
    return render(request, "Dashboard.htm")


def login(request):
    if request.method == 'POST':
        username = request.POST.get("username")
        pwd = request.POST.get("pwd")
        if username == 'lyj' and pwd == '123':
            return HttpResponse("login successfull")
        else:
            return redirect("http://www.runoob.com")

    return render(request, "login.html")


urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^index/', index),
    url(r'^login/', login),  
]
urls.py

相关文章:

  • 2021-05-25
  • 2021-07-23
  • 2021-05-31
  • 2021-05-15
  • 2021-12-21
  • 2021-10-10
  • 2021-07-17
  • 2021-08-17
猜你喜欢
  • 2022-01-04
  • 2021-05-25
  • 2021-10-16
  • 2021-10-15
  • 2021-06-16
  • 2021-10-05
  • 2021-12-19
相关资源
相似解决方案