Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do you configure a Django ImageField with upload_to and MEDIA_ROOT on Webfaction?
    primarykey
    data
    text
    <p>I have the following model field in a django project:</p> <pre><code>headshot = models.ImageField(upload_to='/tmp', blank=True, null=True) </code></pre> <h3>settings.py</h3> <pre><code># format &lt;project&gt;/&lt;app&gt; MEDIA_ROOT = '/home/username/webapps/django/myproject/books/media/' </code></pre> <p>I have created a directory: <code>/home/username/webapps/django/myproject/books/media/tmp</code> and gave it <code>chmod 777</code> permissions.</p> <p>I get the following error when I try to add a new image:</p> <pre><code>SuspiciousOperation at /admin/books/author/add/ Attempted access to '/tmp/Comment.png' denied. Request Method: POST Request URL: http://username.webfactional.com/app/admin/books/author/add/ Django Version: 1.3.1 Exception Type: SuspiciousOperation Exception Value: Attempted access to '/tmp/Comment.png' denied. Exception Location: /home/username/webapps/django/lib/python2.7/django/core/files/storage.py in path, line 234 Python Executable: /usr/local/bin/python Python Version: 2.7.1 </code></pre> <p>Does anyone know what I'm doing wrong? Do I need <code>.htaccess</code> or some other settings to be able to write to this directory or is there something wrong with my Django config?</p> <p>I would still like to know what <code>chmod</code> values to use and how to set <code>MEDIA_URL</code>. I'm thinking I might need to do something in <code>urls.py</code> for <code>MEDIA_URL</code>. </p> <p>My project is set up on the webhost Webfaction if that makes a difference.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload