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 699633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:24:28+00:00 2026-05-14T03:24:28+00:00

I’m fairly new to both Django and Python. This is my first time using

  • 0

I’m fairly new to both Django and Python. This is my first time using forms and upload files with django. I can get the uploads and saves to the database to work fine but it fails to valid email or check if the users selected a file to upload. I’ve spent a lot of time reading documentation trying to figure this out. Thanks!

views.py

def submit_photo(request):
    if request.method == 'POST':
        def store_in_s3(filename, content):
            conn = S3Connection(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)
            bucket = conn.create_bucket(AWS_STORAGE_BUCKET_NAME)
            mime = mimetypes.guess_type(filename)[0] 
            k = Key(bucket)
            k.key = filename
            k.set_metadata("Content-Type", mime)
            k.set_contents_from_file(content)
            k.set_acl('public-read')

        if imghdr.what(request.FILES['image_url']):
            qw = request.FILES['image_url']
            filename = qw.name
            image = filename
            content = qw.file
            url  = "http://bpd-public.s3.amazonaws.com/" + image

            data = {image_url : url, user_email : request.POST['user_email'], user_twittername : request.POST['user_twittername'], user_website : request.POST['user_website'], user_desc : request.POST['user_desc']}
            s = BeerPhotos(data)
            if s.is_valid():
                #import pdb; pdb.set_trace()
                s.save()
                store_in_s3(filename, content)      
                return HttpResponseRedirect(reverse('photos.views.thanks'))
            return s.errors
        else:           
            return errors

    else:
        form = BeerPhotoForm()

    return render_to_response('photos/submit_photos.html', locals(),context_instance=RequestContext(request)

forms.py

class BeerPhotoForm(forms.Form):
    image_url = forms.ImageField(widget=forms.FileInput, required=True,label='Beer',help_text='Select a image of no more than 2MB.')
    user_email = forms.EmailField(required=True,help_text='Please type a valid e-mail address.')
    user_twittername = forms.CharField()
    user_website = forms.URLField(max_length=128,)
    user_desc = forms.CharField(required=True,widget=forms.Textarea,label='Description',)

template.html

<div id="stylized" class="myform">
    <form action="." method="post" enctype="multipart/form-data" width="450px">
        <h1>Photo Submission</h1>
        {% for field in form %}
                {{ field.errors }}
                {{ field.label_tag }} {{ field }}
        {% endfor %}
        <label><span>Click here</span></label>      
    <input type="submit" class="greenbutton" value="Submit your Photo" />
    </form>
</div>
  • 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-14T03:24:29+00:00Added an answer on May 14, 2026 at 3:24 am

    I think the problem is that you are using a forms.ImageField() to validate a url. You may want to be using forms.UrlField().

    Or

    You should not be passing around the url to the file at all. Instead you could be doing s = BeerPhoto(request.POST, request.FILES) and process the file after you run s.is_valid()

    http://docs.djangoproject.com/en/dev/topics/http/file-uploads/

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

Sidebar

Ask A Question

Stats

  • Questions 449k
  • Answers 450k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can't. !important is set on a per property basis… May 15, 2026 at 8:23 pm
  • Editorial Team
    Editorial Team added an answer I guess in case of failure, you are expecting output… May 15, 2026 at 8:23 pm
  • Editorial Team
    Editorial Team added an answer what are attributes? Attributes enable you to embed information about… May 15, 2026 at 8:23 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.