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

  • SEARCH
  • Home
  • 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 8231763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:36:17+00:00 2026-06-07T17:36:17+00:00

I want to set an optional imagefield in my django models. I set blank=True,

  • 0

I want to set an optional imagefield in my django models. I set blank=True, null=True in the imagefields.After inputting the below codes I input an image in all the imagefield except place_4_view. After clicking on the upload button, I’m getting an error. What I’m I missing?

Models

class Findme(models.Model):
   place_2_view=models.ImageField(upload_to="photos",blank=True,null=True)
   place_3_view=models.ImageField(upload_to="photos",blank=True,null=True)
   place_4_view=models.ImageField (upload_to="photos",blank=True,null=True,help_text='Optional.')

Error when uploading

Request Method: POST
Request URL:    http://127.0.0.1:8000/find/
Django Version: 1.4
Exception Type: MultiValueDictKeyError
Exception Value:    "Key 'place_4_view' not found in <MultiValueDict: {u'place_2_view': [<TemporaryUploadedFile: 2012-05-17-289.jpg (image/jpeg)>], u'place_3_view': [<TemporaryUploadedFile: Crimo.JPG (image/jpeg)>]}>"
Exception Location: C:\Python27\lib\site-packages\django\utils\datastructures.py in __getitem__, line 258
Python Executable:  C:\Python27\python.exe

Views

    def findpic(request):
        extra_data_context={}
           #if there's nothing in the field do nothing.
           if request.method=="POST":
              form=FindmeForm(request.POST, request.FILES)
              if form.is_valid():
                 data=form.cleaned_data
                    newfindmes=Findme(
                        user=request.user,
                        pub_date=datetime.datetime.now(),
                        place_2_view=request.FILES['room_2_view'],
                        place_3_view=request.FILES['room_3_view'],
                        place_4_view=request.FILES['room_4_view'])
                    newfindmes.save()
              extra_data_context.update({'FindmeForm':form})
         else:
             form = FindmeForm()
             extra_data_context.update({'FindmeForm':form})
        extra_data_context.update({'Findmes':Findme.objects.filter(user=request.user)})
        return render_to_response('postme.html',extra_data_context,context_instance=RequestContext(request))

Template

        {% block content %}


        <form enctype="multipart/form-data"  form action="." method="POST">
       {% csrf_token %}
             <div class="post-fed">{{ FindmeForm.as_p}}</div>
             <input type="submit" value="Get It"/> 
              </form>



           {% for Findme in Findmes.object_list %}
         <tr>
         <p> {{Findme.pub_date|timesince }} ago </p> 
   <p><img src="{{Findme.thumbnail_2.url}}" width="83" height="78">
    <img src="{{Findme.thumbnail_3.url}}" width="83" height="78"> {% if Findme.thumbnail_4 %} <img src="{{Findme.thumbnail_4.url}}" width="83" height="78"/>
          {% endif %}  
        <p> Created By {{ Findme.user }}</p>
        {% endfor %}
        {% endblock %}
  • 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-06-07T17:36:19+00:00Added an answer on June 7, 2026 at 5:36 pm

    It appears that you have code that expects the key to be in the form during form submission.

    Edit:
    Your findPic method is trying to get the field and the field isn’t there when it is empty. I would recommend the use of request.FILES.get And specify a default value, or test request.FILES for the presence of the keys, or iterate over the keys themselves. Basically your code needs to be prepared for request.FILES To be empty or not contain all the fields you are trying to access.

    See this answer for an example of using request.FILES.get and Files Django Docs for other details on the request.FILES object.

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

Sidebar

Related Questions

How do I set a null value for an optional DateTime parameter in a
I want to set a similar routing to the standard-router with optional parameters, e.g.:
I want set interfaceOrientation in one UIView as LandscapeLeft and Portrait in other UIView.
i want set the visibility to itemized overlay in map view. if the zoom
I want set Listbox background to transparent but not working Is there any idea?
i want set class for repeater when doPostBack for those dataID i wan but
My question is : I have an EditText and I want set a margin
i have a problem, i want set text of a UILabel or UItextView or
i have a multiple marker Google map, it works fine but i want set
I want to set a repeating alarm monthly; but my app resets the alarm

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.