Backend Development Django Subjective
Oct 03, 2025

How do you handle file uploads in Django?

Detailed Explanation
Django file upload handling:\n\n**Model Field:**\n```python\nclass Document(models.Model):\n file = models.FileField(upload_to='documents/')\n image = models.ImageField(upload_to='images/')\n```\n\n**Form Handling:**\n```python\nclass UploadForm(forms.Form):\n file = forms.FileField()\n \n# In view\nif form.is_valid():\n uploaded_file = request.FILES['file']\n```\n\n**Settings:**\n• MEDIA_URL - URL for uploaded files\n• MEDIA_ROOT - Directory for uploaded files\n• FILE_UPLOAD_MAX_MEMORY_SIZE - Memory threshold\n\n**Security:**\n• Validate file types\n• Limit file sizes\n• Scan for malware\n• Use secure file names
Discussion (0)

No comments yet. Be the first to share your thoughts!

Share Your Thoughts
Feedback