Django文件上传表单构造函数解释

时间:2016-06-28 03:06:25

标签: python django

当我浏览Django教程时,我对构造表单的方式感到困惑,这里是以下代码来自的link

forms.py

from django import forms

class UploadFileForm(forms.Form):
    title = forms.CharField(max_length=50)
    file = forms.FileField()

views.py

from django.http import HttpResponseRedirect
from django.shortcuts import render
from .forms import UploadFileForm

# Imaginary function to handle an uploaded file.
from somewhere import handle_uploaded_file

def upload_file(request):
    if request.method == 'POST':
        form = UploadFileForm(request.POST, request.FILES) 
        if form.is_valid():
            handle_uploaded_file(request.FILES['file'])
            return HttpResponseRedirect('/success/url/')
    else:
        form = UploadFileForm()
    return render(request, 'upload.html', {'form': form})

问题:我在哪里可以找到UploadFileForm的构造函数声明?

1 个答案:

答案 0 :(得分:2)