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 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

Related Questions

I'm working on a django app right and I'm using cherrypy as the server.
Hey, i am currently working on a django app for my studies, and came
I'm working on a little django app for reserving prints of paintings. Customers go
I am working on a web application using Python (Django) and would like to
I have a standalone Django app that I'm working on right now. You can
At one point, my Django app needs to load one of its own pages
Am working with django Publisher example, I want to list all the publishers in
I am working on an django application that will return what historically was a
I just got done working through the Django tutorials for the second time, and
I'm working on my first Django application. In short, what it needs to do

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.