getting started - NameError: name 'location' is not defined

1,243 views
Skip to first unread message

Steven Kulesza

unread,
Jun 26, 2014, 3:24:46 PM6/26/14
to django...@googlegroups.com

 I am following along with the getting started guide and i am trying to sync my database after adding the haystack connections (http://django-oscar.readthedocs.org/en/latest/internals/getting_started.html#database) The location class is undefinded.

From settings.py where the error is located:


from oscar import OSCAR_MAIN_TEMPLATE_DIR
TEMPLATE_DIRS = (
    location('frobshop/templates'),
    OSCAR_MAIN_TEMPLATE_DIR,
)


The traceback log:
(oscar)Stevens-MacBook-Pro:frobshop steven$ python manage.py syncdb --traceback
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/steven/.virtualenvs/oscar/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
    utility.execute()
  File "/Users/steven/.virtualenvs/oscar/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/steven/.virtualenvs/oscar/lib/python2.7/site-packages/django/core/management/__init__.py", line 261, in fetch_command
    commands = get_commands()
  File "/Users/steven/.virtualenvs/oscar/lib/python2.7/site-packages/django/core/management/__init__.py", line 107, in get_commands
    apps = settings.INSTALLED_APPS
  File "/Users/steven/.virtualenvs/oscar/lib/python2.7/site-packages/django/conf/__init__.py", line 54, in __getattr__
    self._setup(name)
  File "/Users/steven/.virtualenvs/oscar/lib/python2.7/site-packages/django/conf/__init__.py", line 49, in _setup
    self._wrapped = Settings(settings_module)
  File "/Users/steven/.virtualenvs/oscar/lib/python2.7/site-packages/django/conf/__init__.py", line 128, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/Users/steven/.virtualenvs/oscar/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
    __import__(name)
  File "/Users/steven/Desktop/frobshop/frobshop/settings.py", line 120, in <module>
    location('templates'),
NameError: name 'location' is not defined

Lijo Antony

unread,
Jun 26, 2014, 3:28:50 PM6/26/14
to django-oscar
Hi,

You may have to define a function to get the absolute path to a directory like this

BASE_DIR = os.path.dirname(os.path.dirname(__file__))

location = lambda x: os.path.join(
    os.path.realpath(BASE_DIR), x)

in your settings.py

-lijo



--
https://github.com/tangentlabs/django-oscar
http://django-oscar.readthedocs.org/en/latest/
https://twitter.com/django_oscar
---
You received this message because you are subscribed to the Google Groups "django-oscar" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-oscar...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-oscar.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-oscar/40b822f5-37f2-4376-bd48-2eb81515157b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Steven Kulesza

unread,
Jun 26, 2014, 3:39:31 PM6/26/14
to django...@googlegroups.com
Great, that seem to have solved the location problem. however... I am receiving another error with the COMPRESS_ROOT variable.

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/steven/.virtualenvs/oscar/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
    utility.execute()
  File "/Users/steven/.virtualenvs/oscar/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/steven/.virtualenvs/oscar/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/Users/steven/.virtualenvs/oscar/lib/python2.7/site-packages/django/core/management/base.py", line 284, in execute
    self.validate()
  File "/Users/steven/.virtualenvs/oscar/lib/python2.7/site-packages/django/core/management/base.py", line 310, in validate
    num_errors = get_validation_errors(s, app)
  File "/Users/steven/.virtualenvs/oscar/lib/python2.7/site-packages/django/core/management/validation.py", line 34, in get_validation_errors
    for (app_name, error) in get_app_errors().items():
  File "/Users/steven/.virtualenvs/oscar/lib/python2.7/site-packages/django/db/models/loading.py", line 196, in get_app_errors
    self._populate()
  File "/Users/steven/.virtualenvs/oscar/lib/python2.7/site-packages/django/db/models/loading.py", line 75, in _populate
    self.load_app(app_name, True)
  File "/Users/steven/.virtualenvs/oscar/lib/python2.7/site-packages/django/db/models/loading.py", line 99, in load_app
    models = import_module('%s.models' % app_name)

  File "/Users/steven/.virtualenvs/oscar/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
    __import__(name)
  File "/Users/steven/.virtualenvs/oscar/lib/python2.7/site-packages/compressor/models.py", line 1, in <module>
    from compressor.conf import CompressorConf  # noqa
  File "/Users/steven/.virtualenvs/oscar/lib/python2.7/site-packages/compressor/conf.py", line 8, in <module>
    class CompressorConf(AppConf):
  File "/Users/steven/.virtualenvs/oscar/lib/python2.7/site-packages/appconf/base.py", line 72, in __new__
    new_class._configure()
  File "/Users/steven/.virtualenvs/oscar/lib/python2.7/site-packages/appconf/base.py", line 101, in _configure
    value = callback(value)
  File "/Users/steven/.virtualenvs/oscar/lib/python2.7/site-packages/compressor/conf.py", line 76, in configure_root
    raise ImproperlyConfigured("COMPRESS_ROOT setting must be set")
django.core.exceptions.ImproperlyConfigured: COMPRESS_ROOT setting must be set

I cannot find documentation for this, so your help will be much appreciated

-steven

Lijo Antony

unread,
Jun 26, 2014, 3:46:55 PM6/26/14
to django-oscar
Hi, 

I think you are referring to the documentation for the dev version.

Docs for the latest release version(0.7.x) can be found here.


-lijo

 


Maik Hoepfel

unread,
Jun 27, 2014, 7:24:46 AM6/27/14
to django...@googlegroups.com
On 26/06/14 20:28, Lijo Antony wrote:
> Hi,
>
> You may have to define a function to get the absolute path to a
> directory like this
>
> BASE_DIR = os.path.dirname(os.path.dirname(__file__))
>
> location = lambda x: os.path.join(
> os.path.realpath(BASE_DIR), x)
>
> in your settings.py

Lijo is correct. I've just added it to the docs:
https://github.com/tangentlabs/django-oscar/commit/48e7f5993ea907ea2b54170fcf48b7c72c52db9c
> <mailto:django-oscar...@googlegroups.com>.
> <https://groups.google.com/d/msgid/django-oscar/40b822f5-37f2-4376-bd48-2eb81515157b%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> https://github.com/tangentlabs/django-oscar
> http://django-oscar.readthedocs.org/en/latest/
> https://twitter.com/django_oscar
> ---
> You received this message because you are subscribed to the Google
> Groups "django-oscar" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-oscar...@googlegroups.com
> <mailto:django-oscar...@googlegroups.com>.
> Visit this group at http://groups.google.com/group/django-oscar.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-oscar/CAHK7p71szLc2Wk3W5ThwXq6CDMGTiD-2Qh93sESuEQCOJ6MmQA%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-oscar/CAHK7p71szLc2Wk3W5ThwXq6CDMGTiD-2Qh93sESuEQCOJ6MmQA%40mail.gmail.com?utm_medium=email&utm_source=footer>.
Reply all
Reply to author
Forward
0 new messages