Dear developer,
Please try to setup static files directory in your settings.py file.
It should be a list, like below
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static', 'app'),
os.path.join(BASE_DIR, 'static')
]
Please let me know if you still face this issue.
On Friday, July 22, 2016 at 5:58:57 PM UTC+5:30, [email protected] wrote:
>
> Hey there!
> Sorry for the bother, but I'm running into some issues dealing with static
> files for a new site I'm building with Django. I'm new to django, but I
> swear I went through at least 5 hours of StackOverflow comments and other
> guides before hitting up this group. Anyway:
>
> # The issue:
> Static files are not being served correctly, even though they are
> correctly being collected using the `./manage.py collectstatic`, and placed
> in a `static/` directory under the project root.
>
> # Debugging information
> OS: Ubuntu 16.04 (4.4.0-31-generic)
> Nginx (reverse proxy and serving static file): 1.11.2
> uWSGI (application server): 2.0.13.1
> Django: 1.9.8
>
> # Where my debugging left me
> In my nginx logs I'm finding requests that correctly get through to uWSGI
> (page returns fine, though without static assets), where going manually to
> the URI (www.example.com/static/home/global.css) returns a 404 error.
>
> The nginx error log for the request in question:
>
>> [date_stuff] [error] [log_stuff]: *1 open()
>> "/server/website/<project_name>/static/home/global.css" failed (2: No such
>> file or directory), client: [redacted], server: [redacted], request: "GET
>> /static/home/global.css HTTP/2.0", host: "[redacted]", referrer: "
>> https://www.[redacted]"
>>
>
> Some things that I noticed:
> I don't know how, but the request sent to nginx for the global.css asset
> is trying to get it from
> `/server/website/<project_name>/static/home/global.css`, instead of
> `/server/website/static/home/global.css`.
>
> I'm not sure at that point whether it's an nginx problem or a django one,
> but for some reason the `<project_name>` is being added, and nginx is
> trying to fetch the static files from the wrong place.
>
> # Project overview
> Server/ <----- Located at the root of the machine
> at /server
> ---- Vagrantfile
> ---- db/
> ---- letsencrypt/
> ---- nginx/
> ---- uwsgi/
> ---- website/ <--- Project root
> ---- <project_name>/
> ---- home/ <--- home app
> ---- manage.py/
>
>
> ---- templates/
> ---- static/
> ---- admin/
> ---- home/
> ---- global.css <--- collected from the
> static dir in the `home` app
>
> # <project_name>/settings.py config:
>
>> BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
>>
>
>> INSTALLED_APPS = [
>> 'django.contrib.admin',
>> 'django.contrib.auth',
>> 'django.contrib.contenttypes',
>> 'django.contrib.sessions',
>> 'django.contrib.messages',
>> 'django.contrib.staticfiles',
>> 'home',
>> ]
>>
>
>>
> TEMPLATES = [
>> {
>> 'BACKEND': 'django.template.backends.django.DjangoTemplates',
>> 'DIRS': ['templates'],
>> 'APP_DIRS': True,
>> 'OPTIONS': {
>> 'context_processors': [
>> 'django.template.context_processors.debug',
>> 'django.template.context_processors.request',
>> 'django.contrib.auth.context_processors.auth',
>> 'django.contrib.messages.context_processors.messages',
>> 'django.template.context_processors.static',
>> ],
>> },
>> },
>> ]
>>
>
>>
> STATIC_URL = '/static/'
>> # STATIC_ROOT = os.path.join(BASE_DIR, 'static/') <------ I've tried
>> this and just hardcoding
>>
> STATIC_ROOT = '/server/website/static/'
>>
>
>> # Nginx server config:
>>
> location /static {
> alias /server/website/static; <---- I've tried this and setting
> `root /server/website`
>
>
> Cheers and thanks for any help guys (and sorry for the bother on such a
> beginner question),
> Jason
>
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/0f959216-6d33-405a-b3e9-c0de03b602a2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.