1

I recently had to drop the Django development server and moved to apache because of some problems with the html5 video tag.

The change brought a [Errno 13] Permission denied error when trying to upload a video to the media folder.

I have already set the media folder recursively to 777 with chmod and gave permissions to www-data group with chgrp; here is the output when executing ls -lha media/

total 12K
drwxrwxrwx  3 esteban www-data 4,0K 2012-02-22 06:44 .
drwxr-xr-x 10 esteban esteban  4,0K 2012-02-22 07:35 ..
drwxrwxrwx  3 esteban www-data 4,0K 2012-02-13 10:12 generated

I also wrote the following directive in the httpd.conf file:

<Directory /home/esteban/python_projects/video_transform/media>
Options +Indexes
Order allow,deny
Allow from all
</Directory>

This allows me to list the folder contents when browsing to http://localhost/media but no success with the uploads yet.

Any ideas??

EDIT: The exception is thrown in this line:

destination = open('media/' + filename, 'wb+')
2
  • hmm, have you tried using an absolute path instead of a relative one, just for the sake of testing ? Commented Feb 22, 2012 at 18:08
  • @Paulo Just did and that was it. I'm just not a big fan of burning absolute paths in my code. Anyway that's the way Commented Feb 23, 2012 at 16:29

2 Answers 2

4

Use an absolute path as suggested in comment. Read the documentation at:

http://code.google.com/p/modwsgi/wiki/ApplicationIssues#Application_Working_Directory

as to why.

Sign up to request clarification or add additional context in comments.

2 Comments

Absolutely right. I have to use absolute paths to access anything in the filesystem from my Python code when the Django app is deployed to apache. Thank you very much
For anyone that's also stuck as me (yes, from 2022), use os.path.join(BASE_DIR, ...) for your MEDIA_ROOT and STATIC_ROOT.
0

I would test switching the Order directive in your Apache config. In the current case the deny directive, though not explicitly defined, comes after the Allow directive and effectively blocks all traffic. Switching the Order directive around as such should fix the issue:

<Directory /home/esteban/python_projects/video_transform/media>
Options +Indexes
Order deny,allow
Allow from all
</Directory>

1 Comment

Switching the order results in a 403 error when trying to access anything in the media folder. Thanks for your answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.