--模型.py --
class resmodel(models.Model):
fname = models.CharField(max_length=20)
lname = models.CharField(max_length=20)
file_header = models.CharField(max_length=20)
upload_file = ContentTypeRestrictedFileField(
upload_to='documents', ]
content_types=['documents/msword', 'documents/pdf', 'documents/vnd.oasis.opendocument.text'],
max_upload_size=5242880,blank=True, null=True)
imag = models.ImageField(upload_to='images')
--views.py -- _
def resview(request):
if request.method == "POST":
fname = request.POST.get('fname')
lname = request.POST.get('lname')
file_header = request.POST.get('file_header')
upload_resume = request.FILES['upload_resume']
imag = request.FILES['im']
if upload_file and imag:
details = resmodel(file_header=file_header, fname=fname, lname=lname, upload_file=upload_file, imag=imag)
details.save()
return HttpResponseRedirect('/profile/save/success/')
else:
return render_to_response('file.html')
--文件.html --
<form action="." method="post" enctype="multipart/form-data">{% csrf_token %}
<table border="0" align="center" cellsapcing="1" cellspadding="1">
<tr>
<td colspan="2"><h3> Personal Information</h3></td>
<td>First Name</td>
<td><input type="text" name="fname" /></td>
<td>Last Name</td>
<td><input type="text" name="lname" /></td>
<td>Resume Header<sub>(250 words max)</sub></td>
<td><input type="text" name="file_header"></td>
<td>Upload Resume<sub>(.doc/.docx, rtf, pdf, txt)</sub></td>
<td><input type="file" name="upload_resume" ></td>
<td>Upload image</td>
<td><input type="file" name="im" ></td>
<td>
<input type="submit" value="SUBMIT">
<input type="reset" value="RESET">
</td>
</tr>
</table>
</form>
对于“ContentTypeRestrictedFileField”,我点击了这个链接
但在这里我可以上传 imag 和 upload_file 字段中的所有文件和文件夹。如何限制这个?谁能帮我解决这个问题?谢谢。