Jonathan
I use the attached announce.py to display exactly where all the
directories and URLs are. I had trouble in the beginning getting it
straight in my head but seeing it every time I looked at the dev-server
output helped a lot.
Comments in announce.py show how to use it.
Good luck
Mike
On 12/09/2016 1:58 AM, Jonathan Cheng wrote:
thx reply,but it just can see the original html with no css,is my path
setted correct?
ludovic coues於 2016年9月11日星期日
UTC+8ä¸‹å ˆ11時45分24ç§’å¯«é “ï¼š
Have you tried to add a few newlines to be sure about which line
is the issue ?
Also, in you email, there is a space between % and } in the load
staticfiles tag
2016-09-11 7:29 GMT+02:00 Jonathan Cheng <jonatha...@gmail.com
<javascript:>>:
> I use django1.10
>
> i reference the official doc
> https://docs.djangoproject.com/en/1.10/intro/tutorial06/
<https://docs.djangoproject.com/en/1.10/intro/tutorial06/>
>
> my project name:mysite
>
> structure:
>
> - mysite-
>
> Â Â Â Â Â Â Â - mysite - urls.py
>
> Â Â Â Â Â Â Â Â Â Â Â Â -views.py
>
> Â Â Â Â Â Â Â Â Â Â Â Â ...
>
> Â Â Â Â Â Â Â - templates - index.html
>
> Â Â Â Â Â Â Â Â Â Â Â Â Â - images
> Â Â Â Â Â Â Â - static - mysite - assets - css - main.css
>
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â - js
>
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ...
> In my index.html
>
> add
>
> `{% load staticfiles % }
> Â Â Â Â <link rel="stylesheet" text = 'html/css' href="{%
static
> 'mysite/static/main.css' %}" />`
>
> it said i have a Invalid block tag about TemplateSyntaxError
> `<link rel="stylesheet" type = 'text/css' href="{% static
> 'mysite/static/assets/css/main.css' %}" />`
>
> views.py (about static files part)
> ```STATICFILES_DIRS = [
> Â Â os.path.join(BASE_DIR, "static"),
> Â Â '/mysite/static/',
> ]
> STATIC_URL = '/static/'
> STATIC_ROOT='/mysite/static/'```
>
> what's part should i notice?
>
> --
> 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...@googlegroups.com <javascript:>.
> To post to this group, send email to django...@googlegroups.com
<javascript:>.
> Visit this group at https://groups.google.com/group/django-users
<https://groups.google.com/group/django-users>.
> To view this discussion on the web visit
>
https://groups.google.com/d/msgid/django-users/ef2ea6eb-d1cb-40e2-abef-1af246e02e98%40googlegroups.com
<https://groups.google.com/d/msgid/django-users/ef2ea6eb-d1cb-40e2-abef-1af246e02e98%40googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout
<https://groups.google.com/d/optout>.
--
Cordialement, Coues Ludovic
+336 148 743 42
--
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/a699584c-d57f-4b84-a38b-fe03638caefd%40googlegroups.com
<https://groups.google.com/d/msgid/django-users/a699584c-d57f-4b84-a38b-fe03638caefd%40googlegroups.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/b1119b42-9ca0-4c89-df59-4eb78f562a87%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.
# -*- coding: utf-8 -*-
# Copyright © 2011-2016 Climate Pty Ltd
# SharedSDS is free software subject to the terms of the GNU GPL v3
""" . """
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, backend, caches):
""" 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\n\n%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(":"))
print('Testing: %s' % dbms.replace(":", ""))
else:
print('Database: %s' % databases['default']['HOST'])
print('%s' % backend)
if caches:
print('Cache: %s' % caches['default']['BACKEND'])
timenow = "%s:%02d:%02d" % (dtm.now().hour, dtm.now().minute,
dtm.now().second)
print("%s" % timenow)
def directories(admins, base_dir, settings_dir, media_root, media_url,
static_root, static_url, staticfiles_dirs, template_dirs,
col2=20, col3=40):
""" 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))