On 02/12/2017 12:40 AM, Rafał eM wrote:
Guys,
I'm following one of the Django tutorials but currently stuck with a
problem. When running django webserver on my local machine everything
works fine, but when upload the project to the server it doesn't read
css file anymore.
settings.ps:
|
STATIC_URL ='/static/'
|
base.html:
|
{%load static%}...<link href="{% static 'blog/css/blog.css'
%}"rel="stylesheet"type="text/css">
|
The path to the file is:
|
blog/static/blog/css/blog.css
|
Regardles of configuration I use, I always see in the source:
|
<linkhref="/static/blog/css/blog.css
<http://willhelm.usermd.net/static/blog/css/blog.css>"rel="stylesheet"type="text/css">
|
I've tried with other STATIC constants from django documentation, but
none of them really worked.
However, if I hardcode the css, everything works fine again:
|
<linkhref="static/css/blog.css"rel="stylesheet"type="text/css">
|
Does any of you have any idea on how to solve the issue?
Here is announce.py which helps see where static dirs are in development
and predicts where they will be in production. It could be reworked to
write the results to a log file if used in production.
# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals, print_function
import sys
from datetime import datetime as dtm
from django import get_version
def announce(name,
databases=None,
backend=None,
caches=None,
email_backend=None,
site_id=None,
prdict='production'):
"""
Import announce and directories into settings.py and call each
after all settings involved have been established or in local settings
files which import all base settings
Call it like this ...
if DEBUG:
announce(__name__, databases=DATABASES, backend="Postgres: 9.5",
caches=CACHES)
... where backend is whatever you want as an extra line of info
"""
print("\n\nSettings: %s" % name)
print('Python: %s' % sys.version[0:3])
print('Django: %s' % get_version())
if "sqlite" in databases['default']['ENGINE']:
dbms = "SQLite3"
dbms = "%s in %s" % (dbms, databases['default']['NAME'].strip(":"))
# if SQLite we assume testing
print('Testing: %s' % dbms.replace(":", ""))
else:
print('Database: %s:%s' % (databases['default']['HOST'],
databases['default']['PORT']))
print('%s' % " ".join(backend.split()))
prd = databases.get(prdict, None)
if prd:
print('Database: %s:%s (%s)' % (databases[prdict]['HOST'],
databases[prdict]['PORT'],
prdict.title()))
print('%s (%s)' % (" ".join(databases[prdict]['backend'].split()),
prdict.title()))
print('Engine: %s' % databases['default']['ENGINE'])
if caches:
print('Cache: %s' % caches['default']['BACKEND'])
if email_backend:
print('Email: %s' % email_backend)
if site_id is not None:
print('Site ID: %s' % site_id)
timenow = "%s:%02d:%02d" % (dtm.now().hour, dtm.now().minute,
dtm.now().second)
print("Launched: %s" % timenow)
def directories(admins,
base_dir,
settings_dir,
media_root,
media_url,
static_root,
static_url,
staticfiles_dirs,
template_dirs,
col2=20,
col3=30):
""" Call this from settings.py after all settings involved have been
established or in local settings files which import all base settings
Call it like this ...
if DEBUG:
directories(ADMINS, BASE_DIR, SETTINGS_DIR, MEDIA_ROOT, MEDIA_URL,
STATIC_ROOT, STATIC_URL, STATICFILES_DIRS, TEMPLATE_DIRS)
... and optionally pass in col2 and/or col3 to adjust where columns start
"""
for admin in admins:
sp2 = " " * (col2 - len(admin[0]))
print("\n{0}{1}= {2}".format(admin[0], sp2, admin[1]))
sp3 = " " * (col3 - len(base_dir))
print('BASE_DIR = %s%s%s' % (base_dir, sp3, '(project root)'))
print('SETTINGS_DIR = %s' % settings_dir)
sp3 = " " * (col3 - len(media_root))
print('MEDIA_ROOT = %s%s%s' % (media_root, sp3, '(store uploaded
images)'))
sp3 = " " * (col3 - len(media_url) - 9)
print('MEDIA_URL = <website>%s%s%s' % (media_url, sp3, '(serve
uploaded images)'))
sp3 = " " * (col3 - len(static_root))
print('STATIC_ROOT = %s%s%s' % (static_root, sp3, '(collectstatic
dest)'))
sp3 = " " * (col3 - len(static_url) - 9)
print('STATIC_URL = <website>%s%s%s' % (static_url, sp3, '(serve
css, js etc)'))
for i in enumerate(staticfiles_dirs, 1):
# we can use enumerate here because no sp2 spaces are needed
print('STATICFILES_DIRS# %s = %s' % i)
sp2 = " " * (col2 - 16)
i = 0
for tdir in template_dirs:
i += 1
print('TEMPLATE_DIRS# %s%s= %s' % (i, sp2, tdir))
This is the result in my dev server ...
Settings: ssds.settings.mike-local
Python: 3.5
Django: 1.8.17
Database: localhost:5434
Postgres: 9.5
Engine: django.db.backends.postgresql_psycopg2
Cache: django.core.cache.backends.dummy.DummyCache
Email: django.core.mail.backends.smtp.EmailBackend
Site ID: 3
Launched: 19:31:41
SharedSDS Admin =ad...@dewhirst.com.au
BASE_DIR = C:/Users/mike/env/xxex3/ssds (project root)
SETTINGS_DIR = C:/Users/mike/env/xxex3/ssds/ssds/settings
MEDIA_ROOT = C:/var/www/media/ssds/ (store uploaded images)
MEDIA_URL = <website>/media/ (serve uploaded images)
STATIC_ROOT = C:/var/www/static/ssds/ (collectstatic dest)
STATIC_URL = <website>/static/ (serve css, js etc)
STATICFILES_DIRS# 1 = C:/Users/mike/env/xxex3/ssds/static/
STATICFILES_DIRS# 2 = C:/Users/mike/env/xxex3/ssds/company/static/
STATICFILES_DIRS# 3 = C:/Users/mike/env/xxex3/ssds/substance/static/
STATICFILES_DIRS# 4 = C:/Users/mike/env/xxex3/ssds/workplace/static/
TEMPLATE DIRS# 1 = C:/Users/mike/env/xxex3/ssds/templates/
Performing system checks...
System check identified no issues (0 silenced).
February 12, 2017 - 19:31:42
Django version 1.8.17, using settings 'ssds.settings.mike-local'
Starting development server athttp://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
--
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 django-users+unsubscr...@googlegroups.com
<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to django-users@googlegroups.com
<mailto:django-users@googlegroups.com>.
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/62c6029a-9188-a29e-a720-b54271241dfb%40djangodeployment.com
<https://groups.google.com/d/msgid/django-users/62c6029a-9188-a29e-a720-b54271241dfb%40djangodeployment.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
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/8d1969c9-9058-30eb-71e8-b1a5a62dbd1a%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.