Is it ok that when you run collectstatic with django, python modules are copied as well?

I would like to host a Django application on an Apache server using mod_wsgi.

So far, I've been in a dev environment using a utility to start Django.

I'm surprised that when I run a collective command from Django, the python files are copied to STATIC_ROOT as well. I would expect to only have css and image files ...

Is this normal behavior?

thank

+3


source to share


2 answers


collectstatic just copies all the files it finds to the directories you specify. What exactly this is depends on which search engines you are using ( STATICFILES_FINDERS

in settings.py). By default, an option is included AppDirectoriesFinder

that looks at directories named "static" in your application directories, as well as FileSystemFinder

one that looks at directories specified in a section STATICFILES_DIRS

in your .py settings.

All files in these directories will be copied. Django does not distinguish between Python files (e.g. models, views ...) and other file types. So my guess is that you must have Python files in the wrong directory, or the wrong directory in the search path. You should check your directory structure to solve your problem. However, you can quickly fix this by using ./manage.py collectstatic -i *.py

which, according to the docs , makes collectstatic ignore all files using the .py extension. Haven't tested this though.



I hope this helps.

+1


source


I had the same problem and found that it was because I accidentally forgot the trailing comma in the tuple STATICFILES_DIRS

.

STATICFILES_DIRS = (
    ('', os.path.join(PROJECT_ROOT,'static')), # trailing comma to make this a tuple
)

      



As with Python, without at least one comma in the parentheses, this is interpreted as a function call that confused the setting.

It is generally good practice in Django settings to put a trailing comma in each list and set item, or to use lists exclusively as they don't need commas for individual items.

+1


source







All Articles