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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:04:40+00:00 2026-05-24T06:04:40+00:00

I have a model like this class Ask(models.Model): name = models.CharField(max_length=500) designation = models.CharField(max_length=200,

  • 0

I have a model like this

class Ask(models.Model):
    name = models.CharField(max_length=500)
    designation = models.CharField(max_length=200, blank=True)
    email = models.EmailField()
    phone = models.CharField(max_length=20,  blank=True)
    avatar = models.ImageField(upload_to="ask/users/avaters", blank=True, )
    question = models.CharField(max_length= 1024)
    ques_time = models.DateField(auto_now_add=True)
    answer = models.TextField(blank=True)
    ans_time = models.DateField(blank=True,null=True, auto_now=True)
    display = models.BooleanField()
    asker_ip = models.CharField(max_length=100, blank=True)

    def __unicode__(self):
        return self.name

my forms.py is like this

class AskForm(forms.Form):
    name = forms.CharField(required=True, max_length= 500)
    email = forms.EmailField(required=True)
    avater = forms.ImageField()
    question = forms.CharField(required=True, max_length=1024)

my view is like this

def handle_uploaded_file(f):
    destination = open('D:/dsite/ak47/media/ask/users/avaters', 'wb+')
    for chunk in f.chunks():
        destination.write(chunk)
    destination.close()

def submit_page(request):
    data = {}

    if request.method == 'POST':
        data = request.POST.copy()
        form = AskForm(request.POST, request.FILES)
        if form.is_valid():
            ask = Ask()
            ask.name = form.cleaned_data['name']
            ask.email = form.cleaned_data['email']
            ask.question = form.cleaned_data['question']
            handle_uploaded_file(request.FILES['avater'])
            ask.save()
            return HttpResponseRedirect('/ask/')
        else:
            form = AskForm()

    return  render_to_response('ask/index.html', {'form': form,})

problem is in my windows development server. When I hit submit it give me a io error. Permission denied. I tried give the folder a full control permission. I’m assuming the error is for other reason. Because I can upload from admin panel.

  • 1 1 Answer
  • 2 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-24T06:04:41+00:00Added an answer on May 24, 2026 at 6:04 am

    You’re trying to save file into folder, but did not specified file name.
    Your handle function should be:

    def handle_uploaded_file(f):
        save_path = 'D:/dsite/ak47/media/ask/users/avaters'
        destination = open(os.path.join(save_path,f.name), 'wb+')
        for chunk in f.chunks():
            destination.write(chunk)
        destination.close()
    

    and dont forget add at top of your views.py

    import os
    

    Another solution for this case

    Use ModelForm and it’s features. You dont have to handle manually file uploading, it’s already done by ModelForm. Your forms.py should look like this:

    from .models import Ask
    
    
    class AskForm(forms.ModelForm):
        class Meta:
            model = Ask
            fields = ('name', 'email', 'question', 'avater')
    

    Your views.py should look like this:

    def submit_page(request):
        if request.method == 'POST':
            form = AskForm(request.POST, request.FILES)
            if form.is_valid():
                form.save()
                return HttpResponseRedirect('/ask/')
        else:
            form = AskForm()
    
        return  render_to_response('ask/index.html', {'form': form,})
    

    ModelForm will automagically handle all submitted data and create/save new Ask object for it.

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

Sidebar

Related Questions

I have a simple model like this one: class Artist(models.Model): surname = models.CharField(max_length=200) name
I have a model.py like this: class EventTypeCategory(models.Model): name = models.CharField(max_length=50, verbose_name=Name) user =
I have a model that is something like this: class Input(models.Model): details = models.CharField(max_length=1000)
With Django I have this model: class downloads(models.Model): date = models.CharField(max_length=50) ip = models.ForeignKey(IPaddress)
I have a model class like this: class Note(models.Model): author = models.ForeignKey(User, related_name='notes') content
I have a model that looks like this: class Invite(models.Model): user = models.ForeignKey(User) event
I have a model, smth like this: class Action(models.Model): def can_be_applied(self, user): #whatever return
I've got models like this: class PledgeItem(models.Model): title = models.CharField(...) usd_amount = models.DecimalField(...) class
Let's say I have a model like this class Foo(db.Model): id = db.StringProperty() bar
I'm using MVC3 and I have a model like this: public class Foo {

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.