Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6054359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:08:38+00:00 2026-05-23T08:08:38+00:00

I have this form class in forms.py in my Django application: class EmailForm(EmailFormWithoutAttachment): attachment

  • 0

I have this form class in forms.py in my Django application:

class EmailForm(EmailFormWithoutAttachment):
    attachment = forms.FileField()

I would like to access the file uploaded in forms.py for validation via a clean function to validate its name.

def clean_attachment(self):
    if self.data['attachment'].name == "someFileName.txt":
        raise forms.ValidationError('This file is not allowed.')
    return self.data['attachment']

However, the problem is that an error notes that “attachment” is not found in “QueryDict.” I am binding request.FILES to the submission form. I am also using enctype=”multipart/form-data” on my forms. I was wondering what is the proper way to access FileField data in forms.py.

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T08:08:39+00:00Added an answer on May 23, 2026 at 8:08 am

    Use self.cleaned_data['attachment'] instead of self.data['attachment'].

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Django my_forms.py like this: class CarSearchForm(forms.Form): # lots of fields like
Weird problem in Django with forms : I have a Form.class defined like this
I have a form that looks like this: class SampleForm(forms.Form): text = forms.CharField(max_length=100) In
I have this simple form: class PagoDesde(forms.Form): from django import forms as f desde
I would like to put some help text in this form. class ItemForm(forms.ModelForm): alternative_id
I have a Django Form class defined likes this in Models : class AccountDetailsForm(forms.Form):
I have two questions concerning the Django ChoiceField: This is my form: class ContactForm(forms.Form):
Say I have this simple form: class ContactForm(forms.Form): first_name = forms.CharField(required=True) last_name = forms.CharField(required=True)
I have a simple Django Form: class testForm(forms.Form): list = forms.CharField() def getItems(self): #How
When I define a Django form class similar to this: def class MyForm(forms.Form): check

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.