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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:36:35+00:00 2026-05-12T08:36:35+00:00

I am working on a django app. One part would involve uploading files (e.g.

  • 0

I am working on a django app. One part would involve uploading files (e.g. spreadsheet or whatever). I am getting this error:

IOError at /fileupload/

[Errno 13] Permission denied: 'fyi.xml'

Where ‘fileupload’ was the django app name and ‘fyi.xml’ was the test document I was uploading.

So, I used chmod and chown to make the [project directory]/static/documents/ folder writable to apache. Actually I even tried just making it chmod 777, still no luck.

So, in my settings.py I just changed where my MEDIA_ROOT was:

MEDIA_ROOT = '/var/www/static/'

Then, in case it was an SELinux thing, I created the new documents directory in /var/www/static’…

drwxr-xr-x 2 apache root 4096 Aug 13 11:20 documents

Then I did these commands to try to change the context so apache would be allowed to write here. I’m not too familiar with this distro, it’s the flavor of Red Hat we’re given, so I’ve never had to go beyond chmod and/or chown to fix a permissions problem.

sudo chcon -h system_u:object_r:httpd_sys_content_t /var/www/static
sudo chcon -R -h root:object_r:httpd_sys_content_t /var/www/static
sudo chcon -R -h root:object_r:httpd_sys_content_t /var/www/static/*

None of this made any difference. To be honest, I’m not positive that I even have SELinux here but since normal unix permissions didn’t seem to work I thought I’d try it.

So, does anyone have an idea on what to look at next? Not sure how much code I should post here, but in case it would be helpful here’s what’s in my views.py:

views.py
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response
from forms import UploadFileForm
from fyi.models import Materials

def handle_uploaded_file(f):
    destination = open('fyi.xml', 'wb+')
    for chunk in f.chunks():
        destination.write(chunk)
    destination.close()


def upload_file(request):
    if request.method == 'POST':
        form = UploadFileForm(request.POST, request.FILES)
        if form.is_valid():
            handle_uploaded_file(request.FILES['document'])
            form.save()
            template = 'upload_success.html'
    else:
        form = UploadFileForm()
        template = 'fileupload.html'
    return render_to_response( template, {'form': form})

…any help would be appreciated.

  • 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-12T08:36:35+00:00Added an answer on May 12, 2026 at 8:36 am

    Maybe try changing:

    destination = open('fyi.xml', 'wb+')
    

    to something like:

    upload_dir = settings.MEDIA_ROOT # or wherever
    destination = open(os.path.join(upload_dir, 'fyi.xml'), 'wb+')
    

    If it is an SELinux issue, perhaps this page would help:

    • http://blog.chrisramsay.co.uk/2009/05/22/writing-files-with-django-under-selinux/
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 207k
  • Answers 207k
  • 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 The double-loading of files given to the -i option is… May 12, 2026 at 9:21 pm
  • Editorial Team
    Editorial Team added an answer While I'm at it I may as well write the… May 12, 2026 at 9:21 pm
  • Editorial Team
    Editorial Team added an answer select id from foo inner join bar b1 on b1.fooId=foo.id… May 12, 2026 at 9:21 pm

Related Questions

I am working on an Orbited -powered website and I'm experiencing some annoying behavior
I have worked a bit with Django and I quite like its project/applications model
I'm working on a .NET application (VB 2008) that gets all of its data
So I'm working on an app in Django, however this is my first time

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.