WebFaction
Community site: login faq
0
1

Hi, I am trying to configure settings.py in Django 1.4, but the settings for my uploaded media and static files are wrong. Here is what I have:

MEDIA_ROOT = '/home/<username>/webapps/django/media'
MEDIA_URL = 'http://<username>.webfactional.com/media/'
STATIC_ROOT = '/home/<username>/webapps/django/static_media'
STATIC_URL = 'http://<username>.webfactional.com/static/'

How can I fix this in webfaction on django1.4? Thank you.

asked 22 Apr '12, 20:29

Nick_B
111014
accept rate: 0%


OK, the issue can be solved by applying the same kind of 'static only' application you have for the static media for the uploaded media.

Note the url is the URL to the photo, and that visiting it renders a Django error that the path is not defined. We can bypass Django and make the media served from nginx with a 'symbolic link to static only' type application.

Create the application and in the extra info use the path for the MEDIA_ROOT,

/home/<username>/webapps/django/myproject/media'

Than bind that application to '/media' with the website record. This should solve the problem and serve the media as fast as possible.

permanent link

answered 23 Apr '12, 21:23

johns
5.4k312
accept rate: 23%

edited 28 Apr '12, 20:32

neeravk
1.5k3412

Thanks for your help @johns. Still having problems serving both my static files and my uploaded media, unfortunately.

I have set my settings.py as such:

MEDIA_ROOT = '/home/<username>/webapps/django/myproject/media/'
MEDIA_URL = 'http://<username>.webfactional.com/media'
STATIC_ROOT = '/home/<username>/webapps/myproject/static/'
STATIC_URL = 'http://<username>.webfactional.com/static/'

I believe that I have configured both my static-only app (static) and symbolic link app (media) properly in my webfaction cpanel.

If you visit this link you will witness both problems in action. My css rules are being passed to the browser in the header, but for some reason they aren't being followed.

The uploaded media from the admin site, on the other hand, is not being displayed from (/media/images/<foo>/<bar.jpg>) even though it does exist at:

/home/<username>/webapps/django/myproject/media/images/<foo>/<bar.jpg>

Any help would be appreciated. Thank you.

(27 Apr '12, 06:15) Nick_B

@Nick_B:

Your CSS isn't working because it isn't valid CSS. You need to replace those parentheses with braces, eg change this...

body (
    background-color: red;
    font-family: Verdana, Helvetica;
)

#pageContainer (
    background-color: #d1d1d1;
    margin: 0 auto;
)

... to this ...

body {
    background-color: red;
    font-family: Verdana, Helvetica;
}

#pageContainer {
    background-color: #d1d1d1;
    margin: 0 auto;
}

Regarding your thumbnails, they weren't working because your "media" symlink app wasn't attached to your website. I've fixed that for you and the thumbnails are working now.

Hope that helps!

(27 Apr '12, 15:35) seanf

Awesome thanks @seanf. You answered all of my questions. Thanks for solving my rookie mistakes

(28 Apr '12, 20:24) Nick_B

I just did that. Hope that helps!

(28 Apr '12, 20:33) neeravk

It should be,

MEDIA_ROOT = '/home/<username>/webapps/django/myproject/media'
MEDIA_URL = 'http://<username>.webfactional.com/media/'
STATIC_ROOT = '/home/<username>/webapps/django/myproject/static_media'
STATIC_URL = 'http://<username>.webfactional.com/static/'

Note the extra depth for 'myproject'. You can also set up 'static only' applications to serve the media which is better since its faster. Documentation on how to set up 'static only' apps for your media is here.

permanent link

answered 22 Apr '12, 21:53

johns
5.4k312
accept rate: 23%

I would have to see the links and the site to see what the issue is, but you can normally see it if you view the browser source and look, its normally a missing backslash or something minor missing in the template. You may submit a support ticket if you would like us to take a look and do not want to submit the real URL here.

(23 Apr '12, 19:39) johns

I was following this post to serve my media files through nginx but am not sure if the media is being served by nginx or not, how do I confirm that? Is there anything like collectstatic for media too? This is what I did- 1. created static-only app for static files - seems to be working fine 2. created symbolic app for media files - dont know how to check how media files are being served now but it seems all my media files were copied there.

I think I'm doing it correctly but just wanted to confirm if you could check. My link is <username>.webfactional.com. Also, how do I enable caching of media files? Does nginx automatically does something or I need memchache or other app?

permanent link

answered 25 May '12, 13:18

nistha
21135
accept rate: 0%

Check the root of one of the files,

so say this was your file,

domain.com/static/file.jpg

Visit this URL,

domain.com/static/

If it is nginx you will see a 403 nginx error, if its Apache you will see a Django error.

(25 May '12, 17:38) johns
-1

This may be a bit late, but check at:

ALLOWED_HOSTS = []

in your setting.py. This should be something like:

['<username>.webfactional.com', ]

This is necessary if DEBUG=False.

This is not documented in webfaction, or at least I couldn't find it :-(

permanent link

answered 23 Jul '13, 22:04

Manuel
0
accept rate: 0%

This setting is not mandatory in Django 1.4 so is not the issue in this case. It only became mandatory in Django 1.5 as documented in the Django 1.5 release notes.

(23 Jul '13, 23:30) waynek
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×909
×125
×26
×20
×5

question asked: 22 Apr '12, 20:29

question was seen: 7,939 times

last updated: 23 Jul '13, 23:30

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM