Milkiweed Gtlt
Milkiweed Gtlt

Reputation: 133

Can`t find static files in Django

I have macOS Sierra and I've modified my old Django-project ( project was created on a Linux system, maybe this invoked some bugs )

I have folder static and folder landing inside static

And when I run the server, this is printed out: GET /static/landing/img/397x300/03.jpg HTTP/1.1" 404 1691

this is my settings file with variable static -

STATIC_DIR = os.path.join(BASE_DIR, 'static')
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
    '/Users/milkiweed/Documents/python/django/psy_site/static'

UPD. When I trying to use python3 manage.py collectstatic i have a next problem :

You have requested to collect static files at the destination
location as specified in your settings.

This will overwrite existing files!
Are you sure you want to do this?

Type 'yes' to continue, or 'no' to cancel: yes
Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/milkiweed/Documents/vn/psychology/lib/python3.6/site-    packages/django/core/management/__init__.py", line 364, in     execute_from_command_line
    utility.execute()
  File "/Users/milkiweed/Documents/vn/psychology/lib/python3.6/site-    packages/django/core/management/__init__.py", line 356, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/milkiweed/Documents/vn/psychology/lib/python3.6/site-    packages/django/core/management/base.py", line 283, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/milkiweed/Documents/vn/psychology/lib/python3.6/site-    packages/django/core/management/base.py", line 330, in execute
    output = self.handle(*args, **options)
  File "/Users/milkiweed/Documents/vn/psychology/lib/python3.6/site-    packages/django/contrib/staticfiles/management/commands/collectstatic.py"    , line 199,in handle
    collected = self.collect()
  File "/Users/milkiweed/Documents/vn/psychology/lib/python3.6/site-    packages/django/contrib/staticfiles/management/commands/collectstatic.py"    , line 124,in collect
    handler(path, prefixed_path, storage)
  File "/Users/milkiweed/Documents/vn/psychology/lib/python3.6/site-    packages/django/contrib/staticfiles/management/commands/collectstatic.py"    , line 354,in copy_file
    if not self.delete_file(path, prefixed_path, source_storage):
  File "/Users/milkiweed/Documents/vn/psychology/lib/python3.6/site-    packages/django/contrib/staticfiles/management/commands/collectstatic.py"    , line 260,in delete_file
    if self.storage.exists(prefixed_path):
  File "/Users/milkiweed/Documents/vn/psychology/lib/python3.6/site-    packages/django/core/files/storage.py", line 392, in exists
    return os.path.exists(self.path(name))
  File "/Users/milkiweed/Documents/vn/psychology/lib/python3.6/site-    packages/django/contrib/staticfiles/storage.py", line 50, in path
    raise ImproperlyConfigured("You're using the staticfiles app "
django.core.exceptions.ImproperlyConfigured: You're using the     staticfiles app without having set the STATIC_ROOT setting to a     filesystem path.

Upvotes: 2

Views: 2559

Answers (1)

dirkgroten
dirkgroten

Reputation: 20702

On your development (DEBUG=True) environment, you need two things in settings.py:

STATIC_URL = '/static/'
STATICFILES_DIRS = (os.path.join(BASE_DIR, "static"),)

That should be enough, assuming your static directory is in the BASE_DIR at the top level. If your static directory is somewhere else, adjust STATICFILES_DIRS accordingly.

Upvotes: 7

Related Questions