path of STATICFILES_DIRS in django

I am from PHP background and want to give path to STATICFILES_DIRS in settings.py and in windows I understand that I will need to give full path like: D:/path/to/folder/project/static I want to know that is there a way to give some path like "/static/" or can we give path like dirname(__FILE__) in PHP?

So that my path is not hardcoded. Also why it is physical path as webserver normally don't follow physical path for loading CSS files as it use http path? So why it is this way(physical path) in django? Can some one please explain.

thanks for everyone's effort in advance.

Answers


In my settings.py files, I always do

import os
ROOT_PATH = os.path.dirname(__file__)

Then you can do

STATICFILES_DIRS = [os.path.join(ROOT_PATH, 'static')]

The reason that STATICFILES_DIRS wants a filesystem path is that it needs to know where the files live in the operating system (so things like manage.py collectstatic are possible). The STATIC_URL setting is for webserver paths, and that's what it uses to show to the user in the admin or the {% static %} tag or whatever. STATICFILES_DIRS is server-side only and never shows up in any rendered templates or anything.


Need Your Help

make new python lists with indexes from items in a single list

python list

I want to take a list, e.g. [0, 1, 0, 1, 2, 2, 3], and make a list of lists of (index + 1) for each of the unique elements. For the above, for example, it would be [[1, 3], [2, 4], [5, 6], [7]].

How to change the login name for the current user with Spring Security 3.1?

java spring spring-security

I have the requirement that every user can change his own user name while he stays logged in. The problem is how to update the username (Principal) in Spring Security`s Authentication Token?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.