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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:32:04+00:00 2026-06-10T19:32:04+00:00

I am relatively new to python and Django. The form is displaying itself, but

  • 0

I am relatively new to python and Django.

The form is displaying itself, but when i choose a file and hit save, the form just refreshes itself and the selected file in the FormField disappears and the forms says that this filed is required.

The code is :

models.py

class ScribbleMedia(models.Model):
     media = models.FileField(upload_to='photos')
     def __unicode__(self):
      return self.media
     
class Scribble(models.Model):
     body = models.TextField()
     user = models.ForeignKey(User)
     media = models.ForeignKey(ScribbleMedia)
     def __unicode__(self):
      return u'%s, %s' % (self.user.username, self.media)

class Tag(models.Model):
  name = models.CharField(max_length=64, unique= True)
  scribbles = models.ManyToManyField(Scribble)
  def __unicode__(self):
    return self.name
    

views.py

def scribbler_save_page(request):
    if request.method == 'POST':
        form = ScribbleSaveForm(request.POST)
        if form.is_valid():
            #Create or get media.
            media, dummy = ScribbleMedia.objects.get_or_create(
                media=form.cleaned_data['media']
            )
            #Create or get media.
            scribble, created=Scribble.objects.get_or_create(
                user=request.user,
                media=media
            )
            #update scribble body
            scribble.body=form.cleaned_data['body']
            # If the scibble is being updated, clear old tag list.
            if not created:
                scribble.tag_set.clear()
            # Create new tag list.
            tag_names = form.cleaned_data['tags'].split()
            for tag_name in tag_names:
                tag, dummy = Tag.objects.get_or_create(name=tag_name)
                scribble.tag_set.add(tag)
            # Save scribble to database.
            scribble.save()
            return HttpResponseRedirect ( '/user/%s/' % request.user.username
            )
    else:
        form = ScribbleSaveForm()
    variables = RequestContext (request, { 
        'form': form
    })
    return render_to_response ('scribble_save.html', variables)
    

forms.py

class ScribbleSaveForm(forms.Form):
    media=forms.FileField(
      label=u'add file',
      widget=forms.FileInput()
    )
    text=forms.CharField(
      label=u'description',
      widget=forms.Textarea()
    )
    tags=forms.CharField(
      label=u'Tags',
      required=False,
      widget=forms.TextInput(attrs={'size':64})
    )

urls.py

(r'^save/$', scribbler_save_page),

scribble_save.html

{% extends "base.html" %}
    {% block title %}Save Scribble {% endblock %}
    {% block head %}Save Scribble { % endblock % }
    {% block content %}
    <form method="post" action=".">
        {{ form.as_p }}
        <input type="submit" value="save" />
        {% csrf_token %}
    </form>
    {% 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-10T19:32:05+00:00Added an answer on June 10, 2026 at 7:32 pm

    Two things you need to do specially for file uploads:

    (1) Your HTML form element must include the attribute enctype with the value multipart/form-data.

    <form enctype="multipart/form-data" method="post" action=".">
    

    (2) In your view, you’ll find uploaded files in request.FILES instead of request.POST. To bind uploaded files to your form, pass in request.FILES as the second argument to the form constructor.

    form = ScribbleSaveForm(request.POST, request.FILES)
    

    Source: Django docs – The Forms API – Binding uploaded files to a form

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

Sidebar

Related Questions

I'm relatively new to wxPython (but not Python itself), so forgive me if I've
I am relatively new to python and app engine, and I just finished my
I'm relatively new to python/django. I'm having an issue with sending to IDs through
I'm relatively new to python and know very little syntax, but I'm willing to
I'm relatively new to the Python world, but this seems very straight forward. Google
I'm relatively new to python (but not to programming), and I can't explain the
sorry if this is an obvious question, but I am relatively new to python
I'm relative new to django and in generall to the python world. But I
I am relatively new in python, was working on C a lot. Since I
I'm relatively new to Python and struggling to reconcile features of the language with

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.