I've been digging through articles and posts about this subject but can't seem to get my images to load. For some reason the CSS on my pages seems to load just fine.
settings.py
BASE_DIR = Path(__file__).resolve().parent.parent
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
also I tried
STATIC_ROOT = '/var/www/myname/'
template
<img src="{% static 'picture.jpg' %}" class="img-fluid">
NGINX
/etc/nginx/sites-enabled/django_project
server {
listen 80;
server_name mywebsite.com;
location /static/ {
alias /var/www/myname/static/;
}
}
directories
/var/www/myname
└── static
└── admin
├── css
│ ├── styles1.css
│ └── styles2.css
├── images
│ ├── picture.jpg
│ └── python.jpg
└── js
└── scripts.js
/home/myname/myprojectdir
├── django_project
│ ├── django_project
│ │ └── __pycache__
│ ├── etc
│ ├── index
│ │ ├── migrations
│ │ │ └── __pycache__
│ │ ├── __pycache__
│ │ └── templates
│ │ └── index
│ │ └── backups
│ ├── __pycache__
│ └── static
│ ├── admin
│ │ ├── css
│ │ │ └── vendor
│ │ │ └── select2
│ │ ├── fonts
│ │ ├── images
│ │ │ └── gis
│ │ ├── img
│ │ │ └── gis
│ │ └── js
│ │ ├── admin
│ │ └── vendor
│ │ ├── jquery
│ │ ├── select2
│ │ │ └── i18n
│ │ └── xregexp
│ ├── images
│ └── index
│ ├── css
│ ├── images
│ └── js
├── myname_env
│ ├── bin
│ └── lib
│ └── python3.10
│ └── site-packages
└── static
└── admin
├── css
│ └── vendor
│ └── select2
├── fonts
├── img
│ └── gis
└── js
├── admin
└── vendor
├── jquery
├── select2
│ └── i18n
└── xregexp
I've tried installing the static files in other directories, etc, to see what works but I'm not having any luck whatsoever. I had the static files in the project but after reading that's not a good practice I put them into var/www.
can you add this into nginx conf and try:
location /images/ {
alias /var/www/myname/static/images;
}
Related
My project folder looks this:
├── Procfile
├── core
│ ├── __init__.py
│ ├── __pycache__
│ │ ├── __init__.cpython-39.pyc
│ │ └── views.cpython-39.pyc
│ ├── admin.py
│ ├── apps.py
│ ├── migrations
│ │ └── __init__.py
│ ├── models.py
│ ├── tests.py
│ └── views.py
├── db.sqlite3
├── inspirationSources.txt
├── manage.py
├── package-lock.json
├── package.json
├── react-frontend
│ ├── README.md
│ ├── build
│ │ ├── asset-manifest.json
│ │ ├── favicon.ico
│ │ ├── index.html
│ │ ├── logo192.png
│ │ ├── logo512.png
│ │ ├── manifest.json
│ │ ├── robots.txt
│ │ └── static
│ ├── package-lock.json
│ ├── package.json
│ ├── public
│ │ ├── favicon.ico
│ │ ├── index.html
│ │ ├── logo192.png
│ │ ├── logo512.png
│ │ ├── manifest.json
│ │ └── robots.txt
│ └── src
│ ├── App.css
│ ├── App.js
│ ├── App.test.js
│ ├── assets
│ ├── components
│ ├── hooks
│ ├── index.css
│ └── index.js
├── requirements.txt
├── spotify
│ ├── __init__.py
│ ├── __pycache__
│ │ ├── __init__.cpython-39.pyc
│ │ ├── admin.cpython-39.pyc
│ │ ├── apps.cpython-39.pyc
│ │ ├── cluster.cpython-39.pyc
│ │ ├── credentials.cpython-39.pyc
│ │ ├── models.cpython-39.pyc
│ │ ├── urls.cpython-39.pyc
│ │ ├── util.cpython-39.pyc
│ │ └── views.cpython-39.pyc
│ ├── admin.py
│ ├── apps.py
│ ├── cluster.py
│ ├── credentials.py
│ ├── migrations
│ │ ├── 0001_initial.py
│ │ ├── __init__.py
│ │ └── __pycache__
│ ├── models.py
│ ├── templates
│ ├── tests.py
│ ├── urls.py
│ ├── util.py
│ └── views.py
├── spotifycluster
│ ├── __init__.py
│ ├── __pycache__
│ │ ├── __init__.cpython-39.pyc
│ │ ├── settings.cpython-39.pyc
│ │ ├── urls.cpython-39.pyc
│ │ └── wsgi.cpython-39.pyc
│ ├── asgi.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
└── tutorialSources.txt
When I deploy with git push heroku main it seems to be fine but when I open the app in browser using the complementary url, I get the following errors on screen (debug mode is on):
TemplateDoesNotExist at /
build/index.html
Request Method: GET
Request URL: https://nameless-taiga-02413.herokuapp.com/
Django Version: 3.1.7
Exception Type: TemplateDoesNotExist
Exception Value:
build/index.html
Exception Location: /app/.heroku/python/lib/python3.9/site-packages/django/template/loader.py, line 19, in get_template
Python Executable: /app/.heroku/python/bin/python
Python Version: 3.9.4
Python Path:
['/app/.heroku/python/bin',
'/app',
'/app/.heroku/python/lib/python39.zip',
'/app/.heroku/python/lib/python3.9',
'/app/.heroku/python/lib/python3.9/lib-dynload',
'/app/.heroku/python/lib/python3.9/site-packages']
Server time: Fri, 30 Apr 2021 10:08:26 +0000
Template-loader postmortem
Django tried loading these templates, in this order:
Using engine django:
django.template.loaders.filesystem.Loader: /app/react-frontend/build/index.html (Source does not exist)
django.template.loaders.app_directories.Loader: /app/.heroku/python/lib/python3.9/site-packages/django/contrib/admin/templates/build/index.html (Source does not exist)
django.template.loaders.app_directories.Loader: /app/.heroku/python/lib/python3.9/site-packages/django/contrib/auth/templates/build/index.html (Source does not exist)
I have the following settings in my settings.py
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
Also I have whitenoise in my middleware list
MIDDLEWARE = [
'whitenoise.middleware.WhiteNoiseMiddleware',
...]
The templates section in settings.py looks as follows
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'react-frontend')],
'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',
],
},
},
]
I expected that Heroku would be able to find the static folder based on the STATIC_DIRS variable but that doesn't seem to be the case. Any clue what's going on here?
So actually it was a really stupid mistake. react-frontend was a broken submodule and I needed to fix that by making sure .git/config didn't have submodules and removing react-frontend from the cache (No submodule mapping found in .gitmodules for path and missing .gitmodules file). Commit and pushed again and it worked...
if your DEBUG is set to False Django din't handle STATIC FILES. Heroku provide some configuration to serve STATIC FILES
STEP-1 : install whitenoise
$ pip install whitenoise
STEP-2 : check in settings.py whitenoise middleware by default it available in MIDDLEWARE if it's not that add it.
MIDDLEWARE = (
'whitenoise.middleware.WhiteNoiseMiddleware',
...)
STEP-3: add this in your settings.py
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
I know this has been asked a lot of times but none of the solutions seem to work. I am trying to run a Django app in Heroku but am running into issues when I try to scale dynos.
➜ main-website git:(master) heroku ps:scale web=1
Scaling dynos... !
▸ Couldn't find that process type (web).
The issue seems to be related to ProcFile. This is what I have configured in my root directory (same as requirements.txt etc).
web: gunicorn main-website.wsgi:application --log-file -
What am I missing or doing wrong so I can correct this?
Project Structure
➜ main-website git:(master) tree -L 3
.
├── app
│ ├── about
│ │ ├── admin.py
│ │ ├── apps.py
│ │ ├── __init__.py
│ │ ├── migrations
│ │ ├── models.py
│ │ ├── __pycache__
│ │ ├── tests.py
│ │ ├── urls.py
│ │ └── views.py
│ ├── app
│ │ ├── asgi.py
│ │ ├── __init__.py
│ │ ├── __pycache__
│ │ ├── settings.py
│ │ ├── urls.py
│ │ └── wsgi.py
│ ├── contact
│ │ ├── admin.py
│ │ ├── apps.py
│ │ ├── __init__.py
│ │ ├── migrations
│ │ ├── models.py
│ │ ├── __pycache__
│ │ ├── tests.py
│ │ ├── urls.py
│ │ └── views.py
│ ├── core
│ │ ├── admin.py
│ │ ├── apps.py
│ │ ├── __init__.py
│ │ ├── migrations
│ │ ├── models.py
│ │ ├── __pycache__
│ │ ├── tests
│ │ ├── tests.py
│ │ └── views.py
│ ├── db.sqlite3
│ ├── home
│ │ ├── admin.py
│ │ ├── apps.py
│ │ ├── __init__.py
│ │ ├── migrations
│ │ ├── models.py
│ │ ├── __pycache__
│ │ ├── static
│ │ ├── tests.py
│ │ ├── urls.py
│ │ └── views.py
│ ├── manage.py
│ ├── privacy
│ │ ├── admin.py
│ │ ├── apps.py
│ │ ├── __init__.py
│ │ ├── migrations
│ │ ├── models.py
│ │ ├── __pycache__
│ │ ├── tests.py
│ │ ├── urls.py
│ │ └── views.py
│ ├── static
│ │ ├── app
│ │ ├── css
│ │ ├── images
│ │ └── scripts
│ └── templates
│ ├── about.html
│ ├── contact.html
│ ├── footer.html
│ ├── header.html
│ ├── home.html
│ ├── layout.html
│ ├── privacy.html
│ └── slider.html
├── docker-compose.yml
├── Dockerfile
├── LICENSE
├── ProcFile
└── requirements.txt
The file name is Procfile not ProcFile.
Then try this web: gunicorn main-website.wsgi:application --log-file -
edit: the code to create the zip file and add it to my zip_press_kit field actually works, but i still can't get the url to download it in my template (see points 4 and 5 to see what appends)
1) I have a model:
class Book(models.Model):
...
press_kit = models.FileField(upload_to='press_kit/',
verbose_name="Dossier de presse",
blank=True,
null=True,
default=None)
high_res_cover = models.ImageField(upload_to='high_res_covers/',
verbose_name="Couverture HD",
blank=True)
zip_press_kit = models.FileField(upload_to='zips/',
blank=True,
null=True)
I just gave the fields i'm interested into.
So when i save my new Book object in the django-admin i want to check if i have a high_res_cover OR a press_kit, and if so, create a zip_press_kit that would be a zip file containing the high_res_cover and/or the press_kit.
2) I have a save method:
def save(self, *args, **kwargs):
zip_file_name = f"{slugify(f'{self.title}-{self.id}')}.zip"
if self.high_res_cover or self.press_kit:
with ZipFile(f'{MEDIA_ROOT}zips/{zip_file_name}', 'w') as zip_file:
if self.high_res_cover:
zip_file.write(f'{MEDIA_ROOT}{self.high_res_cover}', os.path.basename(f'{MEDIA_ROOT}/{self.high_res_cover}'))
if self.press_kit:
zip_file.write(f'{MEDIA_ROOT}{self.press_kit}', os.path.basename(f'{MEDIA_ROOT}/{self.press_kit}'))
self.zip_press_kit = File(open(f'{MEDIA_ROOT}/zips/{zip_file_name}', 'rb'))
os.remove(f'{MEDIA_ROOT}/zips/{zip_file_name}')
else:
self.zip_press_kit = None
super(Book, self).save(*args, **kwargs)
This code works when my book already exists and I call save on it but when i want to get the URL of the file in my template i get something like 'localhost:8000/Users/me/Desktop/ProjectFIle.../'.
3) Tree of the project:
.
├── Entremonde
│ ├── __init__.py
│ ├── __pycache__
│ │ ├── __init__.cpython-37.pyc
│ │ ├── settings.cpython-37.pyc
│ │ ├── urls.cpython-37.pyc
│ │ └── wsgi.cpython-37.pyc
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
├── Pipfile
├── Pipfile.lock
├── __pycache__
│ └── manage.cpython-37.pyc
├── books
│ ├── __init__.py
│ ├── __pycache__
│ │ ├── __init__.cpython-37.pyc
│ │ ├── admin.cpython-37.pyc
│ │ ├── apps.cpython-37.pyc
│ │ ├── models.cpython-37.pyc
│ │ ├── urls.cpython-37.pyc
│ │ └── views.cpython-37.pyc
│ ├── admin.py
│ ├── apps.py
│ ├── management
│ │ ├── __init__.py
│ │ ├── __pycache__
│ │ │ └── __init__.cpython-37.pyc
│ │ └── commands
│ │ ├── __init__.py
│ │ ├── __pycache__
│ │ │ ├── __init__.cpython-37.pyc
│ │ │ └── books_init.cpython-37.pyc
│ │ └── books_init.py
│ ├── migrations
│ │ ├── 0001_initial.py
│ │ ├── 0002_book_display.py
│ │ ├── __init__.py
│ │ └── __pycache__
│ │ ├── 0001_initial.cpython-37.pyc
│ │ └── __init__.cpython-37.pyc
│ ├── models.py
│ ├── static
│ │ └── books
│ │ └── js
│ ├── templates
│ │ └── books
│ │ ├── authors.html
│ │ ├── book.html
│ │ └── catalogue.html
│ ├── tests.py
│ ├── urls.py
│ └── views.py
├── contacts
│ ├── __init__.py
│ ├── __pycache__
│ │ ├── __init__.cpython-37.pyc
│ │ ├── admin.cpython-37.pyc
│ │ ├── apps.cpython-37.pyc
│ │ ├── models.cpython-37.pyc
│ │ ├── urls.cpython-37.pyc
│ │ └── views.cpython-37.pyc
│ ├── admin.py
│ ├── apps.py
│ ├── migrations
│ │ ├── 0001_initial.py
│ │ ├── 0002_contact_postal_code.py
│ │ ├── __init__.py
│ │ └── __pycache__
│ │ ├── 0001_initial.cpython-37.pyc
│ │ ├── 0002_contact_postal_code.cpython-37.pyc
│ │ └── __init__.cpython-37.pyc
│ ├── models.py
│ ├── templates
│ │ └── contacts
│ │ ├── contacts.html
│ │ └── esapce-pro.html
│ ├── tests.py
│ ├── urls.py
│ └── views.py
├── db.json
├── manage.py
├── media
│ ├── covers
│ │ ├── ...
│ │ └── 25RUPTURE-Couverture_fisher_600px_web.jpg
│ ├── ebooks
│ ├── high_res_covers
│ │ └── HDj_tschichold-nouvelle_typo-couv.jpg
│ ├── posters_events
│ ├── press_kit
│ │ ├── ...
│ │ └── DPentremonde-dossierdepresse_fisher-2.pdf
│ └── zips
│ └── le-realisme-capitaliste-none.zip
├── news
│ ├── __init__.py
│ ├── __pycache__
│ │ ├── __init__.cpython-37.pyc
│ │ ├── admin.cpython-37.pyc
│ │ ├── apps.cpython-37.pyc
│ │ ├── models.cpython-37.pyc
│ │ ├── urls.cpython-37.pyc
│ │ └── views.cpython-37.pyc
│ ├── admin.py
│ ├── apps.py
│ ├── migrations
│ │ ├── 0001_initial.py
│ │ ├── __init__.py
│ │ └── __pycache__
│ │ ├── 0001_initial.cpython-37.pyc
│ │ └── __init__.cpython-37.pyc
│ ├── models.py
│ ├── templates
│ │ └── news
│ │ └── rencontres.html
│ ├── tests.py
│ ├── urls.py
│ └── views.py
├── static
│ ├── css
│ │ ├── authors.css
│ │ ├── elements.css
│ │ ├── entremonde-style.css
│ │ ├── font.css
│ │ └── style.css
│ └── js
│ ├── author.js
│ └── script.js
└── templates
└── base.html
4) how i import the url in my template (also tried with book.zip_press_kit.url ):
<div id="press-kits">
{% for book in books_with_press_kit %}
{{ book.title }}<br>
{% endfor %}
</div>
5) What i get when i click the link:
Page not found (404)
Request Method: GET
Request URL: http://localhost:8000/Users/pshop/Desktop/Entremonde/media/zips/le-realisme-capitaliste-2_QAeRykR.zip
I am trying to run a Django project using Apache2 mod_wsgi on my Debian 6 machine. This project runs fine if I start this project with the development server. But now I get this error:
Exception Type: ImportError at /
Exception Value: No module named urls
My project name is genalytics. There's only one app called fileupload. I have this available on my settings.py:
ROOT_URLCONF = 'genalytics.urls'
Here's the tree structure of my project:
genalytics/
├── fileupload
│ ├── backend.py
│ ├── backend.pyc
│ ├── backends.py
│ ├── backends.pyc
│ ├── django.wsgi
│ ├── encrypt.py
│ ├── encrypt.pyc
│ ├── forms.py
│ ├── forms.pyc
│ ├── functions.py
│ ├── functions.pyc
│ ├── __init__.py
│ ├── __init__.pyc
│ ├── middleware.py
│ ├── middleware.pyc
│ ├── models.py
│ ├── models.pyc
│ ├── static
│ │ ├── admin
│ │ │ ├── css
│ │ │ │ ├── base.css
│ │ │ │ ├── changelists.css
│ │ │ │ ├── dashboard.css
│ │ │ │ ├── forms.css
│ │ │ │ ├── ie.css
│ │ │ │ ├── login.css
│ │ │ │ ├── rtl.css
│ │ │ │ └── widgets.css
│ │ │ ├── img
│ │ │ │ ├── changelist-bg.gif
│ │ │ │ ├── changelist-bg_rtl.gif
│ │ │ │ ├── chooser-bg.gif
│ │ │ │ ├── tool-right.gif
│ │ │ │ ├── tool-right_over.gif
│ │ │ │ ├── tooltag-add.gif
│ │ │ │ ├── tooltag-add_over.gif
│ │ │ │ ├── tooltag-arrowright.gif
│ │ │ │ └── tooltag-arrowright_over.gif
│ │ │ └── js
│ │ │ ├── actions.js
│ │ │ ├── actions.min.js
│ │ │ ├── admin
│ │ │ │ ├── DateTimeShortcuts.js
│ │ │ │ ├── ordering.js
│ │ │ │ └── RelatedObjectLookups.js
│ │ │ ├── calendar.js
│ │ │ ├── collapse.js
│ │ │ └── urlify.js
│ │ ├── css
│ │ │ ├── datepicker.css
│ │ │ ├── datePicker.css
│ │ │ ├── jquery-ui.css~
│ │ │ ├── pro_dropline.css
│ │ │ ├── pro_dropline_ie.css
│ │ │ ├── screen.css
│ │ │ └── screen.css~
│ │ ├── endless_pagination
│ │ │ └── js
│ │ │ ├── endless.js
│ │ │ ├── endless_on_scroll.js
│ │ │ └── endless-pagination.js
│ │ │ ├── transfer.png
│ │ │ ├── ui-icons_454545_256x240.png
│ │ │ ├── upload.png
│ │ │ └── up.png
│ │ ├── js
│ │ │ ├── endless-pagination.js
│ │ │ ├── jquery
│ │ │ │ ├── Copy of custom_jquery.js
│ │ │ │ ├── custom_jquery.js
│ │ │ │ ├── date.js
│ │ │ │ ├── jquery-1.4.1.min.js
│ │ │ │ ├── jquery.bind.js
│ │ │ │ ├── jquery.datePicker.js
│ │ │ │ ├── jquery.dimensions.js
│ │ │ │ ├── jquery.filestyle.js
│ │ │ │ ├── jquery.pngFix.pack.js
│ │ │ │ ├── jquery.selectbox-0.5.js
│ │ │ │ ├── jquery.selectbox-0.5_style_2.js
│ │ │ │ ├── jquery.selectbox-0.5_style_3.js
│ │ │ │ ├── jquery.tablesorter.js
│ │ │ │ ├── jquery.tooltip.js
│ │ │ │ ├── jquery.usermode.js
│ │ │ │ ├── ui.checkbox.js
│ │ │ │ └── ui.core.js
│ │ │ ├── jquery-1.9.1.js
│ │ │ ├── jquery.js
│ │ │ ├── jquery-latest.js
│ │ │ ├── jquery.pajinate.js
│ │ │ ├── jquery.tablesorter.js
│ │ │ ├── jquery-ui-1.10.3.custom.min.js
│ │ │ ├── test.js~
│ │ │ └── transfer.js
│ │ ├── login.css
│ │ ├── PIE.htc
│ │ ├── style.css
│ │ └── style.css~
│ ├── svn-commit.tmp
│ ├── tasks.py
│ ├── tasks.py~
│ ├── tasks.pyc
│ ├── templates
│ │ ├── ajax.html
│ │ ├── base.html
│ │ ├── create_session.html
│ │ ├── create_session.html~
│ │ ├── deleted_files.html
│ │ ├── edit_session.html
│ │ ├── file_info.html
│ │ ├── footer.html
│ │ ├── forgot_password.html
│ │ ├── form.html
│ │ ├── header.html
│ │ ├── list_files.html
│ │ ├── list_session.html
│ │ ├── list_session.html~
│ │ ├── login_backend.html
│ │ ├── message_forgot.html
│ │ ├── nav.html
│ │ ├── new_password.html
│ │ ├── notify.html
│ │ ├── overview.html
│ │ ├── overview.html~
│ │ ├── password_successful.html
│ │ ├── reform.html
│ │ ├── registration
│ │ │ ├── password_reset_complete.html
│ │ │ ├── password_reset_confirm.html
│ │ │ ├── password_reset_done.html
│ │ │ ├── password_reset_email.html
│ │ │ └── password_reset_form.html
│ │ ├── right.html
│ │ ├── search_result.html
│ │ ├── shared_by_me.html
│ │ ├── shared_with_me.html
│ │ ├── style.css
│ │ ├── synced.html
│ │ ├── test.html
│ │ ├── test.html~
│ │ ├── thanks.html
│ │ ├── uploaded_files.html
│ │ ├── uploaded_files.html~
│ │ └── uploaded_notify.html
│ ├── tests.py
│ ├── views.py
│ ├── views.py~
│ └── views.pyc
├── genalytics
│ ├── __init__.py
│ ├── __init__.pyc
│ ├── settings.py
│ ├── settings.py~
│ ├── settings.pyc
│ ├── urls.py
│ ├── urls.pyc
│ ├── wsgi.py
│ ├── wsgi.py~
│ └── wsgi.pyc
└── manage.py
Content of httpd.conf of Apache:
Listen 8000
<VirtualHost *:8000>
ServerName NFS
DocumentRoot /opt/genalytics
WSGIScriptAlias / /opt/genalytics/genalytics/wsgi.py
<Directory /opt/genalytics/genalytics>
Order allow,deny
Allow from all
</Directory>
Alias /static /opt/genalytics/fileupload/static
</VirtualHost>
wsgi.py content:
import os
import sys
sys.path.append('/opt/genalytics')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "genalytics.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
I am using Django 1.5. Thank you!
You might want to change this line in your wsgi.py:
sys.path.append('/opt/genalytics')
to:
sys.path.insert(0, '/opt/genalytics')
Hi I am trying to integrate foundation scss into django using django-compressor's precompiler, the project looks like this:
├── manage.py
├── requirements.txt
├── static
│ ├── config.rb
│ ├── humans.txt
│ ├── index.html
│ ├── javascripts
│ │ ├── foundation
│ │ │ ├── foundation.alerts.js
│ │ │ ├── foundation.clearing.js
│ │ │ ├── foundation.cookie.js
│ │ │ ├── foundation.dropdown.js
│ │ │ ├── foundation.forms.js
│ │ │ ├── foundation.joyride.js
│ │ │ ├── foundation.js
│ │ │ ├── foundation.magellan.js
│ │ │ ├── foundation.orbit.js
│ │ │ ├── foundation.placeholder.js
│ │ │ ├── foundation.reveal.js
│ │ │ ├── foundation.section.js
│ │ │ ├── foundation.tooltips.js
│ │ │ └── foundation.topbar.js
│ │ └── vendor
│ │ ├── custom.modernizr.js
│ │ ├── jquery.js
│ │ └── zepto.js
│ ├── MIT-LICENSE.txt
│ ├── robots.txt
│ ├── sass
│ │ ├── app.scss
│ │ ├── normalize.scss
│ │ └── _settings.scss
│ └── stylesheets
│ ├── app.css
│ └── normalize.css
├── templates
│ ├── 404.html
│ ├── 500.html
│ ├── admin
│ │ └── base_site.html
│ └── base.html
└── weddings
├── __init__.py
├── __init__.pyc
├── local_settings.py
├── local_settings.pyc
├── settings.py
├── settings.pyc
├── urls.py
├── urls.pyc
└── wsgi.py
and the precompiler looks like this in settings.py
COMPRESS_PRECOMPILERS = (
('text/x-scss', 'sass --scss --compass {infile} {outfile}'),
)
And when I run it with nginx + uwsgi, I get the following error:
Syntax error: File to import not found or unreadable: foundation/foundation-global.
Load paths:
/etc/uwsgi/vassals
/etc/uwsgi/vassals/sass
/srv/www/weddings/gems/compass-0.12.2/frameworks/blueprint/stylesheets
/srv/www/weddings/gems/compass-0.12.2/frameworks/compass/stylesheets
Compass::SpriteImporter
/srv/www/weddings/gems/bourbon-3.1.1/app/assets/stylesheets
/srv/www/weddings/gems/bourbon-3.1.1/app/assets/stylesheets
on line 2 of /srv/www/weddings/weddings/static/sass/_settings.scss
from line 2 of /srv/www/weddings/weddings/static/sass/app.scss
Use --trace for backtrace.
I suspect it's not reading the config.rb or the settings in config.rb is wrong:
http_path = "/"
css_dir = "stylesheets"
sass_dir = "sass"
images_dir = "images"
javascripts_dir = "javascripts"
As you have a config.rb file, you have a Compass project.
Compass projects are supposed to be compiled with the compass command line tool, not sass command line tool.
As you have already discovered, compilation should be launched from insie the project folder. But it's a bad idea to hardcode the path into settings.py as it makes your project unportable.
Instead of a hardcoded path, you should use os.path.dirname(os.path.realpath(__file__)) to discover current script's path. To change the folder relative to settings.py, use os.path.join() like this (adjust as necessary, you can use ..):
os.path.join(os.path.dirname(os.path.realpath(__file__)), "static")
Also, you may already have PROJECT_DIR var in your settings.py. Use it to make this line cleaner.
A little improvement to #James Lin
COMPRESS_PRECOMPILERS = (
# ('text/x-scss', 'django_libsass.SassCompiler'),
# ('text/x-scss', 'sass --scss {infile} {outfile}'),
('text/x-scss', 'sass --scss --compass {infile} {outfile}'),
)
My current work around is to run the sass command in the folder where ocnfig.rb is located
COMPRESS_PRECOMPILERS = (
('text/x-scss', 'cd /srv/www/project/name/static && sass --scss --compass {infile} {outfile}'),
)