markfinger / python-react

Server-side rendering of React components
MIT License
1.62k stars 116 forks source link

basic_rendering example error #57

Closed hqman closed 8 years ago

hqman commented 8 years ago

python example.py

Traceback (most recent call last):
  File "example.py", line 3, in <module>
    from react.render import render_component
File "/Users/hqman/project/pydev/lib/python2.7/site-packages/react/render.py", line 2, in <module>
    from optional_django import staticfiles
  File "/Users/hqman/project/pydev/lib/python2.7/site-packages/optional_django/staticfiles.py", line 2, in <module>
    from .env import DJANGO_CONFIGURED
  File "/Users/hqman/project/pydev/lib/python2.7/site-packages/optional_django/env.py", line 20, in <module>
    getattr(DJANGO_SETTINGS, 'DEBUG', None)
  File "/Users/hqman/project/pydev/lib/python2.7/site-packages/django/utils/functional.py", line 184, in inner
    self._setup()
  File "/Users/hqman/project/pydev/lib/python2.7/site-packages/django/conf/__init__.py", line 40, in _setup
    raise ImportError("Settings cannot be imported, because environment variable %s is undefined." % ENVIRONMENT_VARIABLE)
ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.
markfinger commented 8 years ago

Thanks for reporting that. Looks like a strange error, but django's always full of quirks.

The fix would be effect the line: https://github.com/markfinger/optional-django/blob/master/optional_django/env.py#L20

Would probably need to split the try/except again and catch an ImportError in another block.

@hqman can you run the following and report what it says:

import django
print(django.VERSION)
hqman commented 8 years ago

import django print(django.VERSION) (1, 4, 10, 'final', 0)

markfinger commented 8 years ago

That's a fairly old and unsupported version of Django, so it may be exhibiting different behaviour than the later versions.

Can you try upgrading your django version and seeing if that fixes your issue? pip install -U django

For context, there's a compatibility layer that tries to detect if it's running in a django project, and then allows you to use relative paths that django magically resolves.

hqman commented 8 years ago

thanks @markfinger it works