WebFaction
Community site: login faq
0
1

Despite reading the other questions on here about this, I'm still confused about a couple things: I've created a django app, an admin media app (symbolic link), and a static media app (static only) as per the tutorial. I've set

MEDIA_ROOT = '/home/username/webapps/static_media_app'
MEDIA_URL  = 'http://websiteurl.com/media/'

Why do I set the media variables, but not the STATIC_ROOT and STATIC_URL? the comments in settings.py make it seems like i should be setting the latter to the former's values. Second, how do I use the content of my static app (javascript, css, images etc) in my django templates? {{STATIC_URL}}/path...?

asked 27 Jul '11, 13:28

Pat B
346
accept rate: 0%

edited 27 Jul '11, 13:28


Our documentation has not been updated to Django 1.3 (staticfiles was introduced in the version) and you will need the static settings in your settings.py.

MEDIA_ROOT = '/home/username/webapps/media'  
MEDIA_URL  = '/media/'  
STATIC_ROOT = '/home/username/webapps/static'  
STATIC_URL  = '/static/'

For the static files you will use {{ STATIC_URL }}/path... 
and the media files you will use {{ MEDIA_URL }}/path...

You will use the static files for admin images and css, then use media for items such as user generated uploads.

permanent link

answered 27 Jul '11, 16:24

timg ♦♦
1.3k4
accept rate: 30%

thank you for the response. I have changed the settings.py like you suggest, and to test, i tried just outputting {{ STATIC_URL }} on my site, but nothing shows up. Has the default TEMPLATE_CONTEXT_PROCESSORS setting been overridden somehow?

(27 Jul '11, 17:19) Pat B

Did you restart Apache after making the changes? It is hard to say what the issue could be based on that info alone, you may want to submit a support ticket so we can actually see what the issue is in real-time. I am not quite sure what you mean when you say the defaults for TEMPLATE_CONTEXT_PROCESSORS has changed to affect this in particular. Personally I have been setting both STATIC_ and MEDIA_ for quite a while on my apps as any app that has file uploads typically keeps that in MEDIA while the css, images, and javascript went in STATIC.

(27 Jul '11, 17:31) johns ♦♦

i did restart apache. i will submit a support ticket, thank you

(27 Jul '11, 17:40) Pat B

I had the same problem moving from tutorial-based Django 1.3 development on a local machine to webfaction. I had several problems:

1) I was using a templete request that did not include the settings vars. Change Request to RequestContext and pass the request as first arg, then your own context vars. Then STATIC_URL will be passed correctly: t = loader.get_template('main.html') c = RequestContext(request, { 'foo': bar, 'bar': foo, }) return HttpResponse(t.render(c))

2) I had to add modify my urls.py urlpatterns to remove the leading /. Not sure why. # myapp view support url(r'^$', 'myapp.views.main'),

3) I had to add these to my urls.py: from django.contrib.staticfiles.urls import staticfiles_urlpatterns urlpatterns += staticfiles_urlpatterns()

if settings.DEBUG: urlpatterns += patterns('', (r'^statics/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.STATIC_ROOT}), )

(02 Sep '11, 14:22) AllThumbs
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:

×905
×124
×26
×16

question asked: 27 Jul '11, 13:28

question was seen: 5,102 times

last updated: 02 Sep '11, 14:22

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