I am trying to learn Django,
In settings.py I have set:
MEDIA_ROOT = '/home/hussain/django/ratingsite/ratingsite/media'
MEDIA_URL = 'media/'
STATIC_ROOT = '/home/hussain/django/ratingsite/ratingsite/static'
STATIC_URL = '/static/'
STATICFILES_DIRS = (
'/home/hussain/django/ratingsite/ratingsite/static',)
I have my css files in my
/home/hussain/django/ratingsite/ratingsite/static/css/default.css
but when I try to access the webpage it doesnot load the css and gives Error.
"NetworkError: 500 Internal Server Error - http://localhost:8000/static/css/default.css"
I am new to this so I dont understand what is my root directory. what runs first and how Django tries to find the resources. If someone can guide me through this it would be great.
Guyz Guyz I was just doing hit and try and this happened. I renamed my static folder to staticfiles and then in STATICFILES_DIRS replaced the path from '/home/hussain/django/ratingsite/ratingsite/static/', to '/home/hussain/django/ratingsite/ratingsite/staticfiles/', and it worked. I have No Idea why. can someone please explain ?
output of python manage.py runserver --traceback
hussain#jarvis:~/django/ratingsite$ python manage.py runserver --traceback
Validating models...
0 errors found
December 08, 2013 - 01:48:39
Django version 1.5.4, using settings 'ratingsite.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[08/Dec/2013 01:48:41] "GET / HTTP/1.1" 200 930
Traceback (most recent call last):
File "/usr/lib/python2.7/wsgiref/handlers.py", line 85, in run
self.result = application(self.environ, self.start_response)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/handlers.py", line 73, in __call__
return super(StaticFilesHandler, self).__call__(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 255, in __call__
response = self.get_response(request)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/handlers.py", line 63, in get_response
return self.serve(request)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/handlers.py", line 56, in serve
return serve(request, self.file_path(request.path), insecure=True)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/views.py", line 38, in serve
absolute_path = finders.find(normalized_path)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/finders.py", line 238, in find
for finder in get_finders():
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/finders.py", line 253, in get_finders
yield get_finder(finder_path)
File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 31, in wrapper
result = func(*args)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/finders.py", line 275, in _get_finder
return Finder()
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/finders.py", line 62, in __init__
"The STATICFILES_DIRS setting should "
ImproperlyConfigured: The STATICFILES_DIRS setting should not contain the STATIC_ROOT setting
[08/Dec/2013 01:48:42] "GET /static/css/default.css HTTP/1.1" 500 59
Traceback (most recent call last):
Traceback (most recent call last):
File "/usr/lib/python2.7/wsgiref/handlers.py", line 85, in run
File "/usr/lib/python2.7/wsgiref/handlers.py", line 85, in run
self.result = application(self.environ, self.start_response)
self.result = application(self.environ, self.start_response)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/handlers.py", line 73, in __call__
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/handlers.py", line 73, in __call__
return super(StaticFilesHandler, self).__call__(environ, start_response)
return super(StaticFilesHandler, self).__call__(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 255, in __call__
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 255, in __call__
response = self.get_response(request)
response = self.get_response(request)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/handlers.py", line 63, in get_response
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/handlers.py", line 63, in get_response
return self.serve(request)
return self.serve(request)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/handlers.py", line 56, in serve
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/handlers.py", line 56, in serve
return serve(request, self.file_path(request.path), insecure=True)
return serve(request, self.file_path(request.path), insecure=True)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/views.py", line 38, in serve
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/views.py", line 38, in serve
absolute_path = finders.find(normalized_path)
absolute_path = finders.find(normalized_path)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/finders.py", line 238, in find
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/finders.py", line 238, in find
for finder in get_finders():
for finder in get_finders():
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/finders.py", line 253, in get_finders
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/finders.py", line 253, in get_finders
yield get_finder(finder_path)
yield get_finder(finder_path)
File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 31, in wrapper
File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 31, in wrapper
result = func(*args)
result = func(*args)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/finders.py", line 275, in _get_finder
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/finders.py", line 275, in _get_finder
return Finder()
return Finder()
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/finders.py", line 62, in __init__
File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/finders.py", line 62, in __init__
"The STATICFILES_DIRS setting should "
"The STATICFILES_DIRS setting should "
ImproperlyConfigured: The STATICFILES_DIRS setting should not contain the STATIC_ROOT setting
ImproperlyConfigured: The STATICFILES_DIRS setting should not contain the STATIC_ROOT setting
This makes sense now.
The problem is this as is written in your stacktrace:
ImproperlyConfigured: The STATICFILES_DIRS setting should not contain the STATIC_ROOT setting
And per your initial configuration:
STATIC_ROOT = '/home/hussain/django/ratingsite/ratingsite/static'
STATICFILES_DIRS = (
'/home/hussain/django/ratingsite/ratingsite/static',)
You will not that both of these point to exactly the same directory. This is not allowed for the reason described below.
The ImproperlyConfigured error was fixed when you changed the location of one of these configurations (so they were no longer identical).
The solution here is to:
create a different STATIC_ROOT directory (we'd call this something like /public/static/) do not put any files in this directory this is where all of the static files are automatically collected to when your site is ready to publish.
put the location/s of the files that you are developing in the STATICFILES_DIRS.
When you are ready to publish your project you are able to run $ ./manage.py collectstatic which will go through all the apps and staticfiles directories your project uses and compile a set of all the "final" static files you need in the STATIC_ROOT directory ready for publication with your finished site.
If your STATIC_ROOT directory was included in the directories that was gone through by collectstatic there would obviously be a recursive loop.
Have you added the following to your urls.py?
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = patterns('',
# ... the rest of your URLconf goes here ...
) + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
Per the instructions here:
https://docs.djangoproject.com/en/dev/howto/static-files/
Although you are getting a 500 error which suggests another problem.
What is the output of?:
$ python manage.py validate --traceback
Does this state some other kind of error?
How about the output of:
$ python manage.py shell
>>> from django.conf import settings
>>> print(settings.STATICFILES_DIRS)
As it is returning 500 rather than the expected 404 you could run:
$ python manage.py runserver --traceback
... and then see what the traceback history returns when you load the webpage.
Related
Im running the command python manage.py collectstatic
You have requested to collect static files at the destination
location as specified in your settings:
/static
python manage.py collectstatic
This will overwrite existing files!
Are you sure you want to do this?
Type 'yes' to continue, or 'no' to cancel: yes
the error im gettting;
Can't open file "/static/fonts/FreeSans.ttf"
Copying '/home/mark/Desktop/xls/python-django-exporting-files/static/js/bootstrap.min.js'
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/mark/.virtualenvs/test/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/home/mark/.virtualenvs/test/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/mark/.virtualenvs/test/local/lib/python2.7/site-packages/django/core/management/base.py", line 390, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/mark/.virtualenvs/test/local/lib/python2.7/site-packages/django/core/management/base.py", line 441, in execute
output = self.handle(*args, **options)
File "/home/mark/.virtualenvs/test/local/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 168, in handle
collected = self.collect()
File "/home/mark/.virtualenvs/test/local/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 107, in collect
handler(path, prefixed_path, storage)
File "/home/mark/.virtualenvs/test/local/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 315, in copy_file
self.storage.save(prefixed_path, source_file)
File "/home/mark/.virtualenvs/test/local/lib/python2.7/site-packages/django/core/files/storage.py", line 64, in save
name = self._save(name, content)
File "/home/mark/.virtualenvs/test/local/lib/python2.7/site-packages/django/core/files/storage.py", line 223, in _save
os.makedirs(directory)
File "/home/mark/.virtualenvs/test/lib/python2.7/os.py", line 150, in makedirs
makedirs(head, mode)
File "/home/mark/.virtualenvs/test/lib/python2.7/os.py", line 157, in makedir
mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/static'
The error im gettting in the browser;
Can't open file "/static/fonts/FreeSans.ttf"
TTFError at /
Can't open file "/static/fonts/FreeSans.ttf"
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 1.8.2
Exception Type: TTFError
Exception Value:
Can't open file "/static/fonts/FreeSans.ttf"
STATIC_ROOT = os.path.join(BASE_DIR, '/static/') should be:
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
The / resets tree and it looks for static dir in the root, i.e. literally: /static where you want to have something like /home/user/project/static
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
STATICFILES_DIRS = ( "/home/mark/Desktop/xls/python-django-exporting-files/static", )
try:
from local_settings import *
except:
pass
STATICFILES_DIRS is a place where you keep your own static files that should be collected with collectstatic. It cannot be the same as STATIC_ROOT.
Your structure with static can be like
DJANGO_PROJECT_DIR
|--> PROJECT_DIR
|----> settings.py
|----> templates
|----> static
|--> static
|--> manage.py
Then the code will be (replace PROJECT_DIR with your project dir name):
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATICFILES_DIRS = ( os.path.join(BASE_DIR, 'PROJECT_DIR', 'static'), )
try:
from local_settings import *
except:
pass
I cant get past the first step, setting it up.
This is my settings.py of the application:
MEDIA_URL = '/media/'
MEDIA_ROOT = '/home/django/ristoturisto/media'
FILEBROWSER_DIRECTORY = ''
STATIC_ROOT = '/home/django/ristoturisto/static'
STATIC_URL = '/static/'
FILEBROWSER_DIRECTORY = MEDIA_ROOT
The folders exist, i copied the name from pwd.
I did collect static, that worked.
But when i do:
python manage.py test filebrowser
I get the follwing error:
Creating Test for the FileBrowser site: filebrowser
Creating test database for alias 'default'...
...........F......ERemoving left-over tmp dir: /home/django/ristoturisto/media/tmp_test_0
======================================================================
ERROR: runTest (filebrowser.tests.sites.TestSite_filebrowser)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/filebrowser/tests/sites.py", line 236, in runTest
test_do_upload(self)
File "/usr/lib/python2.6/site-packages/filebrowser/tests/sites.py", line 99, in test_do_upload
response = test.c.post(url, data=f.read(), content_type='application/octet-stream', HTTP_X_REQUESTED_WITH='XMLHttpRequest', X_File_Name='testimage.jpg')
File "/usr/lib/python2.6/site-packages/django/test/client.py", line 449, in post
response = super(Client, self).post(path, data=data, content_type=content_type, **extra)
File "/usr/lib/python2.6/site-packages/django/test/client.py", line 262, in post
return self.request(**r)
File "/usr/lib/python2.6/site-packages/django/core/handlers/base.py", line 111, in get_response
response = callback(request, *callback_args, **callback_kwargs)
File "/usr/lib/python2.6/site-packages/django/contrib/admin/views/decorators.py", line 16, in _checklogin
return view_func(request, *args, **kwargs)
File "/usr/lib/python2.6/site-packages/django/views/decorators/csrf.py", line 77, in wrapped_view
return view_func(*args, **kwargs)
File "/usr/lib/python2.6/site-packages/filebrowser/sites.py", line 476, in _upload_file
file_already_exists = self.storage.exists(file_name)
File "/usr/lib/python2.6/site-packages/django/core/files/storage.py", line 230, in exists
return os.path.exists(self.path(name))
File "/usr/lib/python2.6/site-packages/django/core/files/storage.py", line 246, in path
raise SuspiciousOperation("Attempted access to '%s' denied." % name)
SuspiciousOperation: Attempted access to '/tmp_test_0/testimage.jpg' denied.
======================================================================
FAIL: test_directory (filebrowser.tests.settings.SettingsTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/lib/python2.6/site-packages/filebrowser/tests/settings.py", line 31, in test_directory
self.assertEqual(os.path.basename(DIRECTORY), '')
AssertionError: 'media' != ''
----------------------------------------------------------------------
Ran 19 tests in 3.810s
FAILED (failures=1, errors=1)
Destroying test database for alias 'default'...
The variable MEDIA_ROOT must have trailing slash at the end.
Comment and one line below from django-filebrowser settings file
# DO NOT USE A SLASH AT THE BEGINNING, DO NOT FORGET THE TRAILING SLASH AT THE END.
DIRECTORY = getattr(settings, "FILEBROWSER_DIRECTORY", 'uploads/')
Two lines from settings test where script fail
# Check for trailing slash
self.assertEqual(os.path.basename(DIRECTORY), '')
I faced with some strange problem. When I run single worker for my django application? like this:
python manage.py run_gunicorn -w 1
python manage.py runserver
All requests served correctly, but if start multiple workers like:
python manage.py run_gunicorn -w 10
Django respond with error to (about) half of my requests:
2013-06-13 18:02:39 [10205] [ERROR] Error handling request
Traceback (most recent call last):
File "/home/mezhenin/venv/karma/local/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 130, in handle_request
for item in respiter:
File "/home/mezhenin/venv/karma/local/lib/python2.7/site-packages/raven/middleware.py", line 27, in __call__
iterable = self.application(environ, start_response)
File "/home/mezhenin/venv/karma/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 255, in __call__
response = self.get_response(request)
File "/home/mezhenin/venv/karma/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 177, in get_response
signals.got_request_exception.send(sender=self.__class__, request=request)
File "/home/mezhenin/venv/karma/local/lib/python2.7/site-packages/django/dispatch/dispatcher.py", line 170, in send
response = receiver(signal=self, sender=sender, **named)
File "/home/mezhenin/venv/karma/local/lib/python2.7/site-packages/django/db/__init__.py", line 68, in _rollback_on_exception
transaction.rollback_unless_managed(using=conn)
File "/home/mezhenin/venv/karma/local/lib/python2.7/site-packages/django/db/transaction.py", line 143, in rollback_unless_managed
connection.rollback_unless_managed()
File "/home/mezhenin/venv/karma/local/lib/python2.7/site-packages/django/db/backends/__init__.py", line 232, in rollback_unless_managed
self._rollback()
File "/home/mezhenin/venv/karma/local/lib/python2.7/site-packages/django/db/backends/__init__.py", line 59, in _rollback
return self.connection.rollback()
OperationalError: no connection to the server
I tried sqlite3 as DB backend for Django and it works fine. Do someone have the same problems with psycopg2?
Django==1.5
gunicorn==0.17.2
psycopg2==2.5
Sorry for disturbing. Problem was not in psycopg/Django/gunicorn. I use Nose for testing purposes:
==== settings.py ====
INSTALLED_APPS = INSTALLED_APPS + ('django_nose',)
TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
NOSE_ARGS = ['--with-doctest']
when removed this lines, random errors disappear.
I'm trying to use django-pipeline-1.1.27 with s3boto to compress and filter static files, and then upload them to an s3 bucket. If I just use:
PIPELINE_STORAGE = 'pipeline.storage.PipelineFinderStorage'
Then it works and I get a static folder with the nice versioned file that I configured. As soon as I switch to
PIPELINE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
I get
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_manager(settings)
File "/my/virtual/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/my/virtual/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/my/virtual/env/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/my/virtual/env/lib/python2.7/site-packages/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/my/virtual/env/lib/python2.7/site-packages/pipeline/management/commands/synccompress.py", line 39, in handle
packager.pack_stylesheets(package, sync=sync, force=force)
File "/my/virtual/env/lib/python2.7/site-packages/pipeline/packager.py", line 52, in pack_stylesheets
**kwargs)
File "/my/virtual/env/lib/python2.7/site-packages/pipeline/packager.py", line 60, in pack
package['output'], package['paths'])
File "/my/virtual/env/lib/python2.7/site-packages/pipeline/versioning/__init__.py", line 45, in need_update
version = self.version(paths)
File "/my/virtual/env/lib/python2.7/site-packages/pipeline/versioning/__init__.py", line 20, in version
return getattr(self.versioner, 'version')(paths)
File "/my/virtual/env/lib/python2.7/site-packages/pipeline/versioning/hash/__init__.py", line 37, in version
buf = self.concatenate(paths)
File "/my/virtual/env/lib/python2.7/site-packages/pipeline/versioning/hash/__init__.py", line 27, in concatenate
return '\n'.join([self.read_file(path) for path in paths])
File "/my/virtual/env/lib/python2.7/site-packages/pipeline/versioning/hash/__init__.py", line 31, in read_file
file = storage.open(path, 'rb')
File "/my/virtual/env/lib/python2.7/site-packages/django/core/files/storage.py", line 33, in open
file = self._open(name, mode)
File "/my/virtual/env/lib/python2.7/site-packages/storages/backends/s3boto.py", line 177, in _open
raise IOError('File does not exist: %s' % name)
IOError: File does not exist: css/style.css
which is one of my source files. So why does pipeline no longer want to do the filter/concatenate/compress steps when I switch to s3boto storage?
It may be that I'm doing something. Here is other config in case it helps:
INSTALLED_APPS = (
...
'pipeline',
'storages',
)
STATICFILES_FINDERS = (
'pipeline.finders.PipelineFinder',
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
STATIC_ROOT = "/some/path/outside/django_project/deploy_static"
STATICFILES_DIRS = () # All statics in this site are in apps
STATICFILES_STORAGE = 'pipeline.storage.PipelineStorage'
PIPELINE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
PIPELINE = True
PIPELINE_AUTO = True
PIPELINE_VERSION = True
PIPELINE_VERSION_PLACEHOLDER = 'VERSION'
PIPELINE_VERSIONING = 'pipeline.versioning.hash.SHA1Versioning'
PIPELINE_CSS = {
'standard': {
'source_filenames': (
'css/style.css',
...
),
'output_filename': 'css/all-VERSION.css',
'extra_context': {
'media': 'screen,projection',
},
}
}
My site is on Django 1.3.1.
The command I'm running is:
python manage.py synccompress --force
The AWS creds are also in settings, but that's moot because it's not even getting to that point.
UPDATE Added full stack and settings requested in comments
UPDATE At the request of the library author, I tried upgrading to the latest beta. Observations from that so far:
I don't know how to get versioned compressed files now
collectstatic leaves me with the compressed files and the originals
Still getting the same error from django-pipeline when boto storage is configured: it wants to send my source files to s3, but I can't even see where it's staging my assets. Nothing gets placed in STATIC_ROOT.
UPDATE I've created the simplest project that works for finder storage and then breaks with S3Boto. I've pushed it to github, and included a capture of the stacktrace.
https://github.com/estebistec/simple_pipeline
https://raw.github.com/estebistec/simple_pipeline/master/STACKTRACE
I would be ecstatic if I could be told I'm doing some really dumb and this should all just work.
django-pipeline 1.1.x is a bit dumb about how you should use staticfiles, it prefers to have everything in one place.
I suggest you to try django-pipeline 1.2 with latest django-staticfiles or django 1.4.
Use a custom like this :
STATICFILES_STORAGE = 'your.app.S3PipelineStorage'
The code looks like this :
from staticfiles.storage import CachedFilesMixin
from pipeline.storage import PipelineMixin
from storages.backends.s3boto import S3BotoStorage
class S3PipelineStorage(PipelineMixin, CachedFilesMixin, S3BotoStorage):
pass
You can find how to fix your application, but there is still a bug with compiled files unless you use version 1.2c1 : https://gist.github.com/1999564
I just experienced this same error on a Django 1.6 project with django-pipeline==1.3.23, and the solution was simply removing the PIPELINE_STORAGE setting.
There is another problem with similar error message that affects earlier and current version (1.5.4) of django-pipeline.
The error message is IOError: File does not exist, and it happens in s3boto.py.open() and packager.pack_stylesheets(). You might hit the problem if you use any of the compiler (Compass, Sass, Less etc). I suspect it would also affect JS compiler, but I have not confirmed.
In a nutshell, the compiler generates output file in the local static storage and the next steps, compress is trying to find the output in s3 storage.
If it affects you, you might want to take a look at https://github.com/cyberdelia/django-pipeline/issues/473. There are two pull-requests (patches), one made by skirsdeda and another made by thomasyip (me). Both might solve your problem. If you would like the compiled (but, pre-compressed) file to be copied to s3 and available to the app, the you would take thomasyip (me)'s patch.
Here is full Traceback for the problem:
Traceback (most recent call last):
File "apps/manage.py", line 16, in <module>
execute_from_command_line(sys.argv)
File "/Users/thomas/Dev/Project/main-server/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/Users/thomas/Dev/Project/main-server/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/thomas/Dev/Project/main-server/venv/lib/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Users/thomas/Dev/Project/main-server/venv/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/Users/thomas/Dev/Project/main-server/venv/lib/python2.7/site-packages/django/core/management/base.py", line 533, in handle
return self.handle_noargs(**options)
File "/Users/thomas/Dev/Project/main-server/venv/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 171, in handle_noargs
collected = self.collect()
File "/Users/thomas/Dev/Project/main-server/venv/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 117, in collect
for original_path, processed_path, processed in processor:
File "/Users/thomas/Dev/Project/main-server/venv/lib/python2.7/site-packages/pipeline/storage.py", line 26, in post_process
packager.pack_stylesheets(package)
File "/Users/thomas/Dev/Project/main-server/venv/lib/python2.7/site-packages/pipeline/packager.py", line 96, in pack_stylesheets
variant=package.variant, **kwargs)
File "/Users/thomas/Dev/Project/main-server/venv/lib/python2.7/site-packages/pipeline/packager.py", line 106, in pack
content = compress(paths, **kwargs)
File "/Users/thomas/Dev/Project/main-server/venv/lib/python2.7/site-packages/pipeline/compressors/__init__.py", line 73, in compress_css
css = self.concatenate_and_rewrite(paths, output_filename, variant)
File "/Users/thomas/Dev/Project/main-server/venv/lib/python2.7/site-packages/pipeline/compressors/__init__.py", line 137, in concatenate_and_rewrite
content = self.read_text(path)
File "/Users/thomas/Dev/Project/main-server/venv/lib/python2.7/site-packages/pipeline/compressors/__init__.py", line 220, in read_text
content = self.read_bytes(path)
File "/Users/thomas/Dev/Project/main-server/venv/lib/python2.7/site-packages/pipeline/compressors/__init__.py", line 214, in read_bytes
file = staticfiles_storage.open(path)
File "/Users/thomas/Dev/Project/main-server/venv/lib/python2.7/site-packages/django/core/files/storage.py", line 35, in open
return self._open(name, mode)
File "/Users/thomas/Dev/Project/main-server/venv/lib/python2.7/site-packages/storages/backends/s3boto.py", line 366, in _open
raise IOError('File does not exist: %s' % name)
IOError: File does not exist: sheets/sass/sheets.css
Complementing the answers, you could use GZIP as well when compressing:
from django.contrib.staticfiles.storage import CachedFilesMixin
from pipeline.storage import PipelineMixin
from storages.backends.s3boto import S3BotoStorage
class S3PipelineStorage(PipelineMixin, CachedFilesMixin, S3BotoStorage):
def __init__(self, *args, **kwargs):
self.gzip = True
super(S3PipelineStorage, self).__init__(*args, **kwargs)
Using the settings as follows:
COMPRESS_STORAGE = STATICFILES_STORAGE = 'my.apps.main.S3PipelineStorage'
Not sure how this seemed to work for everyone else. I followed the solution above and kept getting the following error:
Traceback (most recent call last):
File "manage.py", line 24, in <module>
execute_from_command_line(sys.argv)
File "python3.4/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "python3.4/site-packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "python3.4/site-packages/django/core/management/base.py", line 390, in run_from_argv
self.execute(*args, **cmd_options)
File "python3.4/site-packages/django/core/management/base.py", line 441, in execute
output = self.handle(*args, **options)
File "python3.4/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 168, in handle
collected = self.collect()
File "python3.4/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 114, in collect
for original_path, processed_path, processed in processor:
File "python3.4/site-packages/pipeline/storage.py", line 26, in post_process
packager.pack_stylesheets(package)
File "python3.4/site-packages/pipeline/packager.py", line 96, in pack_stylesheets
variant=package.variant, **kwargs)
File "python3.4/site-packages/pipeline/packager.py", line 105, in pack
paths = self.compile(package.paths, force=True)
File "python3.4/site-packages/pipeline/packager.py", line 99, in compile
return self.compiler.compile(paths, force=force)
File "python3.4/site-packages/pipeline/compilers/__init__.py", line 56, in compile
return list(executor.map(_compile, paths))
File "/usr/local/lib/python3.4/concurrent/futures/_base.py", line 549, in result_iterator
yield future.result()
File "/usr/local/lib/python3.4/concurrent/futures/_base.py", line 402, in result
return self.__get_result()
File "/usr/local/lib/python3.4/concurrent/futures/_base.py", line 354, in __get_result
raise self._exception
File "/usr/local/lib/python3.4/concurrent/futures/thread.py", line 54, in run
result = self.fn(*self.args, **self.kwargs)
File "python3.4/site-packages/pipeline/compilers/__init__.py", line 42, in _compile
outdated = compiler.is_outdated(input_path, output_path)
File "python3.4/site-packages/pipeline/compilers/__init__.py", line 85, in is_outdated
return self.storage.modified_time(infile) > self.storage.modified_time(outfile)
File "python3.4/site-packages/storages/backends/s3boto.py", line 480, in modified_time
return parse_ts(entry.last_modified)
AttributeError: 'NoneType' object has no attribute 'last_modified'
It wasn't until I came across this solution that I started to find what worked for me. Here's the storage that I ended up using that saved the file locally as well as in S3 which got me passed all errors:
from django.contrib.staticfiles.storage import ManifestFilesMixin
from django.core.files.storage import get_storage_class
from pipeline.storage import PipelineMixin
from storages.backends.s3boto import S3BotoStorage
class StaticStorage(PipelineMixin, ManifestFilesMixin, S3BotoStorage):
"""Custom storage for static content."""
def __init__(self, *args, **kwargs):
super(StaticStorage, self).__init__(*args, **kwargs)
self.local_storage = get_storage_class(
'django.contrib.staticfiles.storage.StaticFilesStorage')()
def save(self, name, content):
name = super(StaticStorage, self).save(name, content)
self.local_storage._save(name, content)
return name
I'm new to django and Google App Engine, and I'm having trouble with using the datastore. Every time I make a query, such as
db.GqlQuery("SELECT * FROM Listing ORDER BY date DESC LIMIT 10")
I receive the error:
'WSGIRequest' object has no attribute 'user'
This error seems to be generated in context_processors.py within the django core. Now, the advice I've found on the Internet said to comment out user-related INSTALLED_APPS and MIDDLEWARE_CLASSES, but this does not seem to help. My code looks like this:
MIDDLEWARE_CLASSES = (
# 'django.middleware.common.CommonMiddleware',
# 'django.contrib.sessions.middleware.SessionMiddleware',
# 'django.contrib.auth.middleware.AuthenticationMiddleware',
# 'django.middleware.doc.XViewMiddleware',
)
INSTALLED_APPS = (
# 'django.contrib.auth',
'django.contrib.contenttypes',
# 'django.contrib.sessions',
'django.contrib.sites',
)
My Listing object is defined as the following (it had a author property earlier, but this is now commented out and the object was redefined with a new name):
class Listing(db.Model):
#author = db.UserProperty()
address = db.StringProperty()
date = db.DateTimeProperty(auto_now_add=True)
coords = db.GeoPtProperty()
Does anyone know what is causing this error, and how to fix it? Is it perhaps a case of having to reset the settings somehow?
UPDATE
The solution suggested by sdolan seems to be to add the following to the settings.py of the app:
TEMPLATE_CONTEXT_PROCESSORS = (
"django.core.context_processors.debug",
"django.core.context_processors.i18n")
This effectively removes the third default processor, django.core.context_processors.auth (which shouldn't be there because for AppEngine we don't want Django's auth component).
Thank you, sdolan, for the solution! hopefully someone else can use it, too. :)
#Nick, I think it's worth putting this golden piece about CONTEXT_PROCESSORS in the tutorial (http://code.google.com/appengine/articles/django.html)
(Original followup to the question)
Have the same problem, looking for solution.... All works fine when settings.py contains
DEBUG = True
but this error pops up (and kills my motivation to proceed with learning) when I switch to
DEBUG = False
#Nick Johnson, here's the stack trace:
Traceback (most recent call last):
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 3211, in _HandleRequest
self._Dispatch(dispatcher, self.rfile, outfile, env_dict)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 3154, in _Dispatch
base_env_dict=env_dict)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 527, in Dispatch
base_env_dict=base_env_dict)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2404, in Dispatch
self._module_dict)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2314, in ExecuteCGI
reset_modules = exec_script(handler_path, cgi_path, hook)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2212, in ExecuteOrImportScript
script_module.main()
File "C:\Dev\appengine\djangotest\main.py", line 37, in main
util.run_wsgi_app(application)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\webapp\util.py", line 97, in run_wsgi_app
run_bare_wsgi_app(add_wsgi_middleware(application))
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\webapp\util.py", line 115, in run_bare_wsgi_app
result = application(env, _start_response)
File "C:\Program Files (x86)\Google\google_appengine\lib\django\django\core\handlers\wsgi.py", line 189, in __call__
response = self.get_response(request)
File "C:\Program Files (x86)\Google\google_appengine\lib\django\django\core\handlers\base.py", line 103, in get_response
return callback(request, **param_dict)
File "C:\Program Files (x86)\Google\google_appengine\lib\django\django\views\defaults.py", line 79, in page_not_found
return http.HttpResponseNotFound(t.render(RequestContext(request, {'request_path': request.path})))
File "C:\Program Files (x86)\Google\google_appengine\lib\django\django\template\context.py", line 100, in __init__
self.update(processor(request))
File "C:\Program Files (x86)\Google\google_appengine\lib\django\django\core\context_processors.py", line 18, in auth
'user': request.user,
AttributeError: 'WSGIRequest' object has no attribute 'user'