Hello Marcus,
Thank you for your answer. I have made a summary. Please let me know if I
made any mistake.
Greetings, Marcio.
Example of a Mezzanine project (mysite) folder structure with a theme
(theme-01) installed:
C:\SITES
\---mysite
| .gitignore
| .hgignore
| fabfile.py
| manage.py
| requirements.txt
| __init__.py
|
+---deploy
| (...)
|
+---mysite
| | local_settings.py
| | settings.py
| | urls.py
| | wsgi.py
| | __init__.py
| |
| \---static
| \---mysite [Note 1 - C:\SITES\mysite\
mysite\static\mysite\]
| mylogo.jpg
|
+---theme-01
| | __init__.py
| |
| +---static [Note 2 - C:\SITES\mysite\
theme-01\static\]
| | +---css
| | | (...)
| | |
| | +---img
| | | (...)
| | |
| | \---js
| | (...)
| |
| +---templates
| | | base.html
| | | index.html
| | | search_results.html
| | |
| | +---blog
| | | (...)
| | |
| | +---generic
| | | (...)
| | |
| | \---pages
| | (...)
| |
| \---__pycache__
| (...)
|
\---static [Note 3 - C:\SITES\mysite\
static\]
================================================
[Note 1 - C:\SITES\mysite\mysite\static\mysite\]
================================================
[ "mysite APPLICATION STATIC FOLDER" ]
Here you put every image, or other static file, that must show up
on your site, independent of the theme in use. Example: your logo, page's
images, et cetera.
===========================================
[Note 2 - C:\SITES\mysite\theme-01\static\]
===========================================
[ "theme-01 STATIC FOLDER" ]
Here you put the static files used by theme-01: css, js,
index.html, base.html, et cetera.
==================================
[Note 3 - C:\SITES\mysite\static\]
==================================
[ "STATIC_ROOT FOLDER" ]
This folder is automatically populated. Don't put anything here
manually.
On a production environment, it is better to let Django serve the
dynamic content, and let your host's own web server to serve the static
files. To make this easier, every static file of a web site project must be
on a single folder. The staticcollect command searches all the installed
apps and copy theirs static files to the STATIC_ROOT folder
(C:\SITES\mysite\static\ in this example). So the web serve can serve
static content from this single folder.
After adding or changing any file on "mysite application static
folder" or "theme-01 static folder", the following commands must be issued,
to copy all the static files to the STATIC_ROOT folder. If STATIC_ROOT
folder does not exist yet, collectstatic will create it.
cd \SITES\mysite
python manage.py collectstatic
=====================
Configuration and Use
=====================
C:\SITES\mysite\mysite\settings.py must be edited, and "mysite" and
"theme-01" applications added to the top of the INSTALLED_APPS, enabling
their static files be collected by collectstatic command, and reunited on
"mysite project static folder".
INSTALLED_APPS = (
"mysite",
"theme-01",
"django.contrib.admin",
"django.contrib.auth",
...
On your templates, use this to show an image from the "mysite
application static folder":
<img src="{% static "mysite/mylogo.jpg" %}" >
And use this to show an image from the "theme-01 static folder"
(and img subfolder):
<img src="{% static "img/1.jpg" %}" >
Remember to collect static files now:
cd \SITES\mysite
python manage.py collectstatic
Go there and check the folder structure created by collectstatic on
C:\SITES\mysite\static\. It must be more or less like this:
C:\SITES\MYSITE\STATIC
| robots.txt
|
+---admin [admin app static files]
| (...)
|
+---mysite [mysite app static files]
| mylogo.jpg
|
+---css [theme-01 css files]
| (...)
|
+---filebrowser
| (...)
| |
+---grappelli
| (...)
|
+---img [theme-01 img files]
| (...)
|
+---js [theme-01 js files]
| (...)
|
+---mezzanine
| (...)
|
\---test
(...)
The collectstatic command copies the contents of every static
folder, as they are, to the STATIC_ROOT folder. This is the reason you are
advised to put the mysite app static files on
C:\SITES\mysite\mysite\static\mysite, and NOT on
C:\SITES\mysite\mysite\static.
This way, here inside STATIC_ROOT, you can have a distinct "mysite"
folder, separated from the other folders related to the theme and the other
installed apps.
--
You received this message because you are subscribed to the Google Groups
"Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.