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 490k
  • Answers 490k
  • 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 First of all, it's a really bad idea to use… May 16, 2026 at 9:17 am
  • Editorial Team
    Editorial Team added an answer If you are not dead set on using a listbox,… May 16, 2026 at 9:17 am
  • Editorial Team
    Editorial Team added an answer killproc will terminate programs in the process list which match… May 16, 2026 at 9:17 am

Trending Tags

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

Top Members

Related Questions

Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a French site that I want to parse, but am running into

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.