You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.3 KiB
39 lines
1.3 KiB
from django.shortcuts import render |
|
from .forms import * |
|
|
|
|
|
def userinfo_form(request): |
|
if request.method == "GET": |
|
myform = UserInfoForm() |
|
return render(request, "form_demo/userinfo.html", {'form_obj': myform}) |
|
else: |
|
f = UserInfoForm(request.POST) |
|
if f.is_valid(): |
|
print(f.clean()) |
|
print(f.cleaned_data['username']) |
|
print(f.data) |
|
else: |
|
errors = f.errors |
|
print(errors) |
|
return render(request, "form_demo/userinfo.html", {'form_obj': f, 'errors': errors}) |
|
return render(request, "form_demo/userinfo.html", {'form_obj': f}) |
|
|
|
|
|
def img_file_form(request): |
|
if request.method == 'GET': |
|
f = ImgFileForm() |
|
return render(request, "form_demo/uploadimg.html", {'form_obj': f}) |
|
else: |
|
f = ImgFileForm(request.POST, request.FILES) |
|
print(request.POST) |
|
print(request.FILES) |
|
if f.is_valid(): |
|
name = f.cleaned_data['name'] |
|
heading = f.cleaned_data['heading'] |
|
userimg = ImgFile() |
|
userimg.name = name |
|
userimg.heading = heading |
|
userimg.save() |
|
print('上传成功') |
|
print(userimg.heading) |
|
return render(request, 'form_demo/uploadimg.html', {'form_obj': f, 'user_img': userimg})
|
|
|