This is my first time with serverless aka AWS lambda.
Here is my directory tree 1st and 2nd level
$ tree -L 2
.
├── README.md
├── Visualization_Sarit
│ ├── BA_Read0DDataPlot1DGraph.py
│ ├── CC_ReadNew2DDataPlotLineGraph.py
│ ├── ModulesInterfaceTASK.py
│ ├── Visualization.docx
│ ├── Visualization.xlsx
│ └── inHT6Ms302
├── apps
│ ├── advanced_cases
│ ├── commons
│ ├── control_params
│ ├── device_params
│ ├── heating_params
│ ├── plasma_params
│ ├── plasma_species
│ ├── results
│ ├── scenarios
│ └── transport_params
├── experiments.py
├── f1
│ ├── README.md
│ ├── package-lock.json
│ ├── package.json
│ ├── public
│ └── src
├── ht6m
│ ├── __init__.py
│ ├── __pycache__
│ ├── api_urls.py
│ ├── celery.py
│ ├── db_routers.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
├── manage.py
├── media
├── requirements.in
├── requirements.txt
├── static
├── static_files
├── templates
│ ├── __init__.py
│ └── hello.html
└── zappa_settings.json
Here is my settings
settings.py
DEBUG = True
ALLOWED_HOSTS = ['*']
# Application definition
INSTALLED_APPS = [
'django_celery_results',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_extensions',
'django_rq',
'django_filters',
'corsheaders',
'rest_framework',
'apps.advanced_cases',
'apps.commons',
'apps.control_params',
'apps.device_params',
'apps.heating_params',
'apps.plasma_params',
'apps.plasma_species',
'apps.results',
'apps.scenarios',
'apps.transport_params',
]
MIDDLEWARE = [
'corsheaders.middleware.CorsMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
zappa_settings.json
{
"dev": {
"django_settings": "ht6m.settings",
"profile_name": "aegon",
"project_name": "ht6minterface",
"runtime": "python3.7",
"s3_bucket": "zappa-20j5uvs5p",
"aws_region": "ap-southeast-1"
}
}
Deployment went smooth and suddenly raises 502
$ zappa deploy dev
Calling deploy for stage dev..
Creating ht6minterface-dev-ZappaLambdaExecutionRole IAM Role..
Creating zappa-permissions policy on ht6minterface-dev-ZappaLambdaExecutionRole IAM Role.
Downloading and installing dependencies..
- psycopg2-binary==2.8.2: Downloading
100%|█████████████████████████████████████████████████████████████████████████████████████| 2.94M/2.94M [00:01<00:00, 1.95MB/s]
- greenlet==0.4.15: Downloading
100%|██████████████████████████████████████████████████████████████████████████████████████| 42.4K/42.4K [00:00<00:00, 492KB/s]
- gevent==1.4.0: Downloading
100%|█████████████████████████████████████████████████████████████████████████████████████| 5.44M/5.44M [00:01<00:00, 5.01MB/s]
- cffi==1.12.3: Downloading
100%|███████████████████████████████████████████████████████████████████████████████████████| 431K/431K [00:00<00:00, 1.48MB/s]
- sqlite==python3: Using precompiled lambda package
'python3.7'
Packaging project as zip.
Uploading ht6minterface-dev-1559645572.zip (42.2MiB)..
100%|█████████████████████████████████████████████████████████████████████████████████████| 44.2M/44.2M [00:22<00:00, 1.96MB/s]
Scheduling..
Scheduled ht6minterface-dev-zappa-keep-warm-handler.keep_warm_callback with expression rate(4 minutes)!
Uploading ht6minterface-dev-template-1559645689.json (1.6KiB)..
100%|█████████████████████████████████████████████████████████████████████████████████████| 1.65K/1.65K [00:00<00:00, 17.7KB/s]
Waiting for stack ht6minterface-dev to create (this can take a bit)..
100%|███████████████████████████████████████████████████████████████████████████████████████████| 4/4 [00:16<00:00, 5.44s/res]
Deploying API Gateway..
Error: Warning! Status check on the deployed lambda failed. A GET request to '/' yielded a 502 response code.
I don't see any error in the zappa tail
$ zappa tail
Calling tail for stage dev..
[1559645713491] Instancing..
File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlockededdule
[1559645730278] [DEBUG] 2019-06-04T10:55:30.278Z 466c2217-3fd7-4a2e-b97c-732866c5df54 Zappa Event: {'time': '2019-06-04T10:54:50Z', 'detail-type': 'Scheduled Event', 'source': 'aws.events', 'account': '530403937392', 'region': 'ap-southeast-1', 'detail': {}, 'version': '0', 'resources': ['arn:aws:events:ap-southeast-1:530403937392:rule/ht6minterface-dev-zappa-keep-warm-handler.keep_warm_callback'], 'id': 'c2ccca98-e69a-2f19-c398-4d123d24956c', 'kwargs': {}}
[1559645730279] [DEBUG] 2019-06-04T10:55:30.279Z 466c2217-3fd7-4a2e-b97c-732866c5df54 Zappa Event: {}
[1559645731280]
[1559645970227] [DEBUG] 2019-06-04T10:59:30.227Z ad604f41-5692-47b0-8e49-894f52afc56f Zappa Event: {'time': '2019-06-04T10:58:50Z', 'detail-type': 'Scheduled Event', 'source': 'aws.events', 'account': '530403937392', 'region': 'ap-southeast-1', 'detail': {}, 'version': '0', 'resources': ['arn:aws:events:ap-southeast-1:530403937392:rule/ht6minterface-dev-zappa-keep-warm-handler.keep_warm_callback'], 'id': '166fb665-ec39-526e-6ccb-47f1d8f083d3', 'kwargs': {}}
[1559645970227] [DEBUG] 2019-06-04T10:59:30.227Z ad604f41-5692-47b0-8e49-894f52afc56f Zappa Event: {}
[1559645971229]
Where am I wrong?
You're getting 502 because once deployed with API gateway, API gateway requires a very specific response from the Lambda, otherwise it will throw you a Malformed Lambda proxy response aka 502.
As mentioned in the documentation, you should make sure your Lambda is returning a response in the following structure (this must be a JSON):
{
"isBase64Encoded": true|false,
"statusCode": httpStatusCode,
"headers": { "headerName": "headerValue", ... },
"body": "..."
}
Move the apps according to jonvaughan
Another reference
Here is my working directory structure
$ tree -L 2
.
├── README.md
├── Visualization_Sarit
│ ├── BA_Read0DDataPlot1DGraph.py
│ ├── CC_ReadNew2DDataPlotLineGraph.py
│ ├── ModulesInterfaceTASK.py
│ ├── Visualization.docx
│ ├── Visualization.xlsx
│ └── inHT6Ms302
├── __init__.py
├── __pycache__
│ ├── api_urls.cpython-36.pyc
│ ├── celery_ht6m.cpython-36.pyc
│ ├── db_routers.cpython-36.pyc
│ ├── settings.cpython-36.pyc
│ ├── urls.cpython-36.pyc
│ └── wsgi.cpython-36.pyc
├── api_urls.py
├── apps
│ ├── __init__.py
│ ├── __pycache__
│ ├── advanced_cases
│ ├── commons
│ ├── control_params
│ ├── device_params
│ ├── heating_params
│ ├── plasma_params
│ ├── plasma_species
│ ├── results
│ ├── scenarios
│ └── transport_params
├── celery_ht6m.py
├── db_routers.py
├── experiments.py
├── f1
│ ├── README.md
│ ├── package-lock.json
│ ├── package.json
│ ├── public
│ └── src
├── manage.py
├── media
├── requirements.in
├── requirements.txt
├── settings.py
├── static
├── static_files
├── templates
│ ├── __init__.py
│ └── hello.html
├── urls.py
├── wsgi.py
└── zappa_settings.json
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 wrote a small program for Google appengine on the python for a standard environment using google-cloud-pubsub. I get an error
ImportError: cannot import name types. I also saw that the problem is still not solved . But maybe someone started a sub-pub in a standard environment?
I install lib: pip installall -t lib google-cloud-pubsub.
In appengine_config.py: vendor.add('lib')
Error accessing the appengine application:
Traceback (most recent call last):
File "/base/alloc/tmpfs/dynamic_runtimes/python27g/7894e0c59273b2b7/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/base/alloc/tmpfs/dynamic_runtimes/python27g/7894e0c59273b2b7/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "/base/alloc/tmpfs/dynamic_runtimes/python27g/7894e0c59273b2b7/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 85, in LoadObject
obj = __import__(path[0])
File "/base/data/home/apps/e~pqcloud-sp/agg2:20180703t012034.410851540172441919/service_main.py", line 5, in <module>
from google.cloud.pubsub_v1 import PublisherClient
File "/base/data/home/apps/e~pqcloud-sp/agg2:20180703t012034.410851540172441919/lib/google/cloud/pubsub_v1/__init__.py", line 17, in <module>
from google.cloud.pubsub_v1 import types
ImportError: cannot import name types
app.yaml:
runtime: python27
api_version: 1
threadsafe: true
service: agg2
handlers:
- url: .*
script: service_main.app
libraries:
- name: webapp2
version: "2.5.1"
- name: jinja2
version: latest
skip_files:
- ^(.*/)?#.*#$
- ^(.*/)?.*~$
- ^(.*/)?.*\.py[co]$
- ^(.*/)?.*/RCS/.*$
- ^(.*/)?\..*$
service_main.py:
import os
import logging
import webapp2
from google.cloud.pubsub_v1 import PublisherClient
logger = logging.getLogger('service_main')
logger.setLevel(logging.WARNING)
class ServiceTaskMainHandler(webapp2.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'application/json'
self.response.out.write('test')
config = {
'webapp2_extras.sessions': {
'secret_key': 'YOUR_SECRET_KEY'
}
}
MAIN_ROUTE = [
webapp2.Route('/', ServiceTaskMainHandler, name='main'),
]
app = webapp2.WSGIApplication(MAIN_ROUTE, debug=True, config=config)
tree lib/google/cloud/pubsub_v1
lib/google/cloud/pubsub_v1
├── exceptions.py
├── exceptions.pyc
├── futures.py
├── futures.pyc
├── gapic
│ ├── __init__.py
│ ├── __init__.pyc
│ ├── publisher_client_config.py
│ ├── publisher_client_config.pyc
│ ├── publisher_client.py
│ ├── publisher_client.pyc
│ ├── subscriber_client_config.py
│ ├── subscriber_client_config.pyc
│ ├── subscriber_client.py
│ └── subscriber_client.pyc
├── _gapic.py
├── _gapic.pyc
├── __init__.py
├── __init__.pyc
├── proto
│ ├── __init__.py
│ ├── __init__.pyc
│ ├── pubsub_pb2_grpc.py
│ ├── pubsub_pb2_grpc.pyc
│ ├── pubsub_pb2.py
│ └── pubsub_pb2.pyc
├── publisher
│ ├── batch
│ │ ├── base.py
│ │ ├── base.pyc
│ │ ├── __init__.py
│ │ ├── __init__.pyc
│ │ ├── thread.py
│ │ └── thread.pyc
│ ├── client.py
│ ├── client.pyc
│ ├── exceptions.py
│ ├── exceptions.pyc
│ ├── futures.py
│ ├── futures.pyc
│ ├── __init__.py
│ └── __init__.pyc
├── subscriber
│ ├── client.py
│ ├── client.pyc
│ ├── futures.py
│ ├── futures.pyc
│ ├── __init__.py
│ ├── __init__.pyc
│ ├── message.py
│ ├── message.pyc
│ ├── _protocol
│ │ ├── bidi.py
│ │ ├── bidi.pyc
│ │ ├── dispatcher.py
│ │ ├── dispatcher.pyc
│ │ ├── heartbeater.py
│ │ ├── heartbeater.pyc
│ │ ├── helper_threads.py
│ │ ├── helper_threads.pyc
│ │ ├── histogram.py
│ │ ├── histogram.pyc
│ │ ├── __init__.py
│ │ ├── __init__.pyc
│ │ ├── leaser.py
│ │ ├── leaser.pyc
│ │ ├── requests.py
│ │ ├── requests.pyc
│ │ ├── streaming_pull_manager.py
│ │ └── streaming_pull_manager.pyc
│ ├── scheduler.py
│ └── scheduler.pyc
├── types.py
└── types.pyc
The reason your code failed is because App Engine Standard's Python2.7 runtime does not support Pub/Sub Cloud Client Library, only Pub/Sub API Client Library. There's some new code samples showing how to use Pub/Sub with App Engine Standard.
import googleapiclient.discovery
import base64
service = build('pubsub', 'v1')
topic_path = 'projects/{your_project_id}/topics/{your_topic}'
service.projects().topics().publish(
topic=topic_path, body={
"messages": [{
"data": base64.b64encode(data)
}]
}).execute()
Update: Both GAE (Google App Engine) Standard and GAE Flexible Python 3 Runtime support Cloud Pub/Sub Client Library.
I'm completely new for django and I'd want to list the apps of a django project, for example:
FeinCMS
I know that startapp creates the directory structure for an app. I wonder if there is either a function or a file to get the app list.
For example taking FeinCMS as an example, the repo contains:
feincms
├── AUTHORS
├── CHANGELOG.rst
├── CONTRIBUTING.rst
├── docs
│ ├── admin.rst
│ ├── advanced
│ ├── conf.py
│ ├── contenttypes.rst
│ ├── contributing.rst
│ ├── deprecation.rst
│ ├── extensions.rst
│ ├── faq.rst
│ ├── images
│ ├── index.rst
│ ├── installation.rst
│ ├── integration.rst
│ ├── Makefile
│ ├── medialibrary.rst
│ ├── migrations.rst
│ ├── page.rst
│ ├── releases
│ ├── settings.rst
│ ├── templatetags.rst
│ └── versioning.rst
├── feincms
│ ├── admin
│ ├── apps.py
│ ├── content
│ ├── contents.py
│ ├── context_processors.py
│ ├── contrib
│ ├── default_settings.py
│ ├── extensions
│ ├── __init__.py
│ ├── _internal.py
│ ├── locale
│ ├── management
│ ├── models.py
│ ├── module
│ ├── shortcuts.py
│ ├── signals.py
│ ├── static
│ ├── templates
│ ├── templatetags
│ ├── translations.py
│ ├── urls.py
│ ├── utils
│ └── views
├── LICENSE
├── MANIFEST.in
├── README.rst
├── setup.cfg
├── setup.py
└── tests
├── cov.sh
├── manage.py
├── requirements.txt
├── testapp
└── tox.ini
How can I use django to list the apps in the repo?
settings.INSTALLED_APPS is the list of apps. You can start a django shell (manage.py shell) to query the settings:
from django.conf import settings
print(settings.INSTALLED_APPS)
>>> ['user', 'django.contrib.auth', 'django.contrib.sites', ...]
Query django.apps ...
from django.apps import apps
for app in apps.get_app_configs():
print(app, app.name, app.label)
Results in ...
<ContentTypesConfig: contenttypes> django.contrib.contenttypes contenttypes
<AdminConfig: admin> django.contrib.admin admin
I am working on a project to customize the startproject command to create django projects from project_template, see below:
bootstrap/
├── __init__.py
├── conf
│ ├── __init__.py
│ └── project_template
│ ├── manage.py
│ ├── project_name
│ │ ├── __init__.py
│ │ ├── apps
│ │ │ ├── __init__.py
│ │ │ └── example
│ │ │ ├── __init__.py
│ │ │ ├── admin.py
│ │ │ ├── models.py
│ │ │ ├── tests.py
│ │ │ ├── urls.py
│ │ │ └── views.py
│ │ ├── contrib
│ │ │ └── __init__.py
│ │ ├── settings
│ │ │ ├── __init__.py
│ │ │ ├── base.py
│ │ │ ├── development.py
│ │ │ └── production.py
│ │ ├── urls.py
│ │ └── wsgi.py
│ ├── requirements
│ │ ├── base.txt
│ │ ├── development.txt
│ │ └── production.txt
│ ├── requirements.txt
│ ├── static
│ │ ├── js
│ │ │ └── base.js
│ │ ├── scss
│ │ │ └── base.scss
│ │ └── vendor
│ │ └── README
│ └── templates
│ ├── 404.html
│ ├── 500.html
│ ├── base.html
│ └── example
│ ├── base.html
│ └── index.html
└── management
├── __init__.py
└── commands
├── __init__.py
└── startproject.py
this is the startproject.py
import os
import grabone as go
from django.core.management.commands.startproject import Command as StartprojectCommand
EXTENSIONS = ['py', 'txt', 'html', 'scss', 'css', 'js', 'bowerrc', 'rst']
class Command(StartprojectCommand):
def handle(self, project_name=None, target=None, *args, **options):
options['extensions'] += EXTENSIONS
return StartprojectCommand.handle(self, project_name=project_name, target=target, *args, **options)
def handle_template(self, template, subdir):
if template is None:
return os.path.join(go.__path__[0], 'conf', subdir)
return StartprojectCommand.handle_template(self, template, subdir)
When I run django-admin startproject test1 it creates the project folder etc etc, but it will try to parse the html templates and give me an error:
django.template.base.TemplateSyntaxError: 'staticfiles' is not a valid tag library: Template library staticfiles not found, tried django.templatetags.staticfiles
This is what the template looks like:
{% load staticfiles %}
<html>
...
</html>
This is what the INSTALLED_APPS in setting look like:
DJANGO_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
)
THIRD_PARTY_APPS = (
'django_extensions',
'pipeline',
# Add third party apps here
)
LOCAL_APPS = (
# Add local apps here
)
# See: https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps
INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS
Some how the content in the settings is not being executed though...
removed html from
EXTENSIONS = ['py', 'txt', 'html', 'scss', 'css', 'js', 'bowerrc', 'rst']
Worked.
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}'),
)