r4fek / django-cassandra-engine

Django Cassandra Engine - the Cassandra backend for Django
BSD 2-Clause "Simplified" License
365 stars 84 forks source link

static files not served if django_cassandra_engine is the first item in INSTALLED_APPS #22

Closed nq-ebaratte closed 8 years ago

nq-ebaratte commented 9 years ago

The README file recommends setting django_cassandra_engine as the first app in INSTALLED_APPS; for some reason, it seems to break static file service by django.contrib.staticfiles (at least in development mode).

As a workaround, I set 'django.contrib.staticfiles' as the 1st app, then django_cassandra_engine as the 2nd. Is it safe to do so ? Is it a known issue ?

r4fek commented 9 years ago

django.contrib.staticfiles app overrides runserver command and django-cassandra-engine does this too. I believe it will work as long as you use only Cassandra database in your project. I have to find a way to deal with this problem though. Thanks for reporting!

r4fek commented 9 years ago

@nq-ebaratte Could you try it now?

nq-ebaratte commented 9 years ago

It indeed fixes the bug; though it introduces a new one:

    Traceback (most recent call last):
      File "/workspace/django/manage.py", line 10, in <module>
        execute_from_command_line(sys.argv)
      File "/workspace/venv2/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
        utility.execute()
      File "/workspace/venv2/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 377, in execute
        self.fetch_command(subcommand).run_from_argv(self.argv)
      File "/workspace/venv2/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 238, in fetch_command
        klass = load_command_class(app_name, subcommand)
      File "/workspace/venv2/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 41, in load_command_class
        module = import_module('%s.management.commands.%s' % (app_name, name))
      File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
        __import__(name)
      File "/workspace/venv2/local/lib/python2.7/site-packages/django_cassandra_engine/management/commands/runserver.py", line 10, in <module>
        class Command(RunserverCmd):
    TypeError: Error when calling the metaclass bases
        str() takes at most 1 argument (3 given)
r4fek commented 9 years ago

Could you provide django version and INSTALLED_APPS list with DATABASES setting?

nq-ebaratte commented 9 years ago

I use Django 1.7.6, with python 2.7.8. INSTALLED_APPS = ( 'django.contrib.staticfiles', 'django_cassandra_engine', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'my_application' ) [EDIT] there is a mistake here, the actual INSTALLED_APPS showing the bug is:

    INSTALLED_APPS = (
        'django_cassandra_engine',
        'django.contrib.staticfiles',
        'django.contrib.admin',
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.messages',
        'my_application'
    )
r4fek commented 9 years ago

And django_cassandra_engine is your default or secondary db backend?

nq-ebaratte commented 9 years ago

Secondary; I use an sqlite db as 'default'.

r4fek commented 9 years ago

Well, that's weird:

~/projects/django-cassandra-engine/testproject$ python manage.py runserver --settings=settings.secondary_cassandra

Performing system checks...

System check identified no issues (0 silenced).

You have unapplied migrations; your app may not work properly until they are applied.
Run 'python manage.py migrate' to apply them.

March 11, 2015 - 14:32:03
Django version 1.7.6, using settings 'settings.secondary_cassandra'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

I have staticfiles app higher than django_cassandra_engine on INSTALLED_APPS list.

nq-ebaratte commented 9 years ago

Indeed; the new bug happens when setting 'django_cassandra_engine' as the very first installed app (I edited my previous mistaken comment)

cuerty commented 9 years ago

Not a fix, but for anyone else blocked by this issue: you can use django-extension's RunServerPlus until a fix is available.

bbirand commented 9 years ago

Same issue here..

EzequielAdrianM commented 8 years ago

Django is not good for serving media and static files. Try using Nginx as the proxy that handles /static/ and /media/ directories.

rinatio commented 8 years ago

Same issue. Placing django_cassandra_engine after django.contrib.staticfiles works as long as cassandra is a secondary DB:

INSTALLED_APPS = (
    'django.contrib.staticfiles',
    'django_cassandra_engine',
    ...
}