STATIC_ROOT in Django on the server

I am stuck for 2 hours about STATIC_URL and STATIC_ROOT when I try to run webapp on my server in webfactional.

when I load a web page, all requests work well, except that any link with {{STATIC_URL}} is working or loading.

So the general error that occurs in firebug is this:

GET http://mydomain/static/extras/h5bp/js/libs/modernizr-2.5.3.min.js 500 (Internal Server Error) 

My setup:

urls.py I did nothing and there was nothing about static files.

settings.py DEBUG = False

 STATIC_ROOT = '/home/mydomain/webapps/static_app/' STATIC_URL = 'http://mydomain/static/' STATICFILES_DIRS = () 

views.py view example

 @csrf_exempt def IndexView(request): try: request.user.is_authenticated() except AttributeError: return render_to_response('index.html', {'request': request,}, context_instance=RequestContext(request)) return render_to_response('index.html', {'request': request, 'profile' : request.user}, context_instance=RequestContext(request)) 

index.html code portion not found

 <script src="{{ STATIC_URL }}extras/h5bp/js/libs/modernizr-2.5.3.min.js"></script> 

Ok, I follow all the points: https://docs.djangoproject.com/en/1.4/howto/static-files/ and this is another one: http://docs.webfaction.com/software/django/getting-started. html

I use the correct installed applications, middlewares, template_contexts.

If I am missing something, help me figure it out.

Thanks in advance!

- change

I have to say if I just changed DEBUG = True will work fine.

because on urls.py I have this piece of code:

 if settings.DEBUG: # static files (images, css, javascript, etc.) urlpatterns += patterns('', (r'^media/(?P<path>.*)/$', 'django.views.static.serve', { 'document_root': settings.MEDIA_ROOT})) 
+7
source share
1 answer

2 things must happen in a production environment that is not required in a development environment.

You must run manage.py collectstatic - this collects all the static files into your STATIC_ROOT directory.

You must maintain your STATIC_ROOT directory at STATIC_URL . How exactly depends on your production installation. It is not even related to django; all that matters is that the contents of STATIC_ROOT available in STATIC_URL .

Suppose you are using Apache, you would specify the URL of the directory.

 Alias /static/ /path/to/my/static_root/ 

If you use nginx, it will be something like

 location = /static/ { alias /path/to/my/static_root/; } 

I just realized that you are using webfaction, and in this case you are setting up a static application that literally just serves the files in the destination directories at the URL you specify. I try to remember my login to enter webfaction to see the exact procedure, but it is not difficult to understand.

Update: Logged into webfaction; You can create an application, a symbolic link. Easy!

Create a symlink application that serves / YOUR_STATIC_URL / and hover / YOUR _STATIC_ROOT / on it. Done!

+11
source

All Articles