Reputation: 107
ive got a problem here. When i try to "collectstatic" from manage.py it just kicks me off with following error:
Traceback (most recent call last):
File "C:\Program Files (x86)\JetBrains\PyCharm 3.1.3\helpers\pycharm\django_manage.py", line 23, in <module>
run_module(manage_file, None, '__main__', True)
File "C:\Python34\lib\runpy.py", line 182, in run_module
return _run_module_code(code, init_globals, run_name, mod_spec)
File "C:\Python34\lib\runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "C:\Python34\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:/Users/mszalewski/PycharmProjects/OwnPixel_com\manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line 399, in execute_from_command_line
utility.execute()
File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python34\lib\site-packages\django\core\management\base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\Python34\lib\site-packages\django\core\management\base.py", line 285, in execute
output = self.handle(*args, **options)
File "C:\Python34\lib\site-packages\django\core\management\base.py", line 415, in handle
return self.handle_noargs(**options)
File "C:\Python34\lib\site-packages\django\contrib\staticfiles\management\commands\collectstatic.py", line 173, in handle_noargs
collected = self.collect()
File "C:\Python34\lib\site-packages\django\contrib\staticfiles\management\commands\collectstatic.py", line 103, in collect
for path, storage in finder.list(self.ignore_patterns):
File "C:\Python34\lib\site-packages\django\contrib\staticfiles\finders.py", line 106, in list
for path in utils.get_files(storage, ignore_patterns):
File "C:\Python34\lib\site-packages\django\contrib\staticfiles\utils.py", line 25, in get_files
directories, files = storage.listdir(location)
File "C:\Python34\lib\site-packages\django\core\files\storage.py", line 250, in listdir
for entry in os.listdir(path):
FileNotFoundError: [WinError 3] Das System kann den angegebenen Pfad nicht finden: 'C:\\Users\\mszalewski\\PycharmProjects\\static\\static'
Process finished with exit code 1
The following is my settings.py:
import os
import os.path
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
DEBUG = True
TEMPLATE_DEBUG = True
ALLOWED_HOSTS = []
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = 'OwnPixel_com.urls'
WSGI_APPLICATION = 'OwnPixel_com.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
STATIC_URL = '/static/'
TEMPLATE_DIRS = (
os.path.join(os.path.dirname(BASE_DIR), "static", "templates").replace('\\','/')
)
if DEBUG:
MEDIA_URL = '/media/'
STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), "static", "static-only").replace('\\', '/')
MEDIA_ROOT = os.path.join(os.path.dirname(BASE_DIR), "static", "media").replace('\\', '/')
STATICFILES_DIRS = (
os.path.join(os.path.dirname(BASE_DIR), "static", "static").replace('\\', '/'),
)
At least my extendes urls.py
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL,
document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL,
document_root=settings.MEDIA_ROOT)
Iam very sure that its the double backslash in the path (at the end of the error code).
I hope you can help me to fix my problem.
THANKS!!!
Regards, Marvyn
Upvotes: 0
Views: 2973
Reputation: 1961
Because you are in a virtual directory (assuming you've already activated the virtual env like so : source <*Scripts* or *bin*>/activate
), the path that STATIC_ROOT
and STATICFILES_DIRS
expect are different.
1) STATIC_ROOT
is expecting the location of the static files on your local machine (whether that be the cloud server you are serving these files on the computer that you are developing on) --> i.e. something like STATIC_ROOT = 'C:/Users/<user>/Desktop/django_env_folder/mysite/static/mysite'
2) STATICFILES_DIRS
on the other hand is expecting the virtual_env path (remember, when you activate your virtual env using the command above, the paths that os.<method>()
requires are different (do some debugging to see, try running os.listdir('C:/....')
and you will notice different results than expected. SO try something like this for STATICFILES_DIRS --> STATICFILES_DIRS = [
'mysite/static/mysite',
]
** This solution definitely works when serving on localhost
, make sure Debug = True
in your settings.py
.
Upvotes: 0
Reputation:
What does your Directory structure actually look like?
I doubt that 'C:\Users\mszalewski\PycharmProjects\static\static' is the folder you're intending to use for the Project specific static files.
My guess is that you want to change
os.path.join(os.path.dirname(BASE_DIR), "static", "static").replace('\\', '/')
to
os.path.join(BASE_DIR, "static", "static")
Or something very similar. And don't worry about the '\\' and '/'. Python will actually get along just fine with some very odd combinations of them in the same path.
Upvotes: 2