form表单(文件上传)
在生成input标签的时候可以指定input标签的类型为file类型 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <h4>{{ error_message }}</h4> <form action="/index/" method="post"> {% csrf_token %} <p><input type="file" name="up_file"></p> <input type="submit"> </form> </body> </html> 此时,在网页上页示如下 如果网页上提交的是用户名和密码等,通过键值对发送到服务端。 一组键值代表一个标签及标签对应的值。 在网页上选择一张图片,并使用 post 方式提交,在服务端打印 request.POST def index(request): if request.method=="POST": print(request.POST) return render(request,"index.html",locals()) 打印的信息如下: <QueryDict: {'csrfmiddlewaretoken': ['opmSmENIrgdGJJN'], 'up_file':