Having problem with Django application using Pycharm Professional - django

I started a django project yesterday using pyCharm professional as text editor. Very thing was working well before I shoutdown my system. But after I restart my system, I started getting this error.
Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm 2020.1.3\plugins\python\helpers\pycharm\django_manage.py", line 59, in <module>
run_command()
File "C:\Program Files\JetBrains\PyCharm 2020.1.3\plugins\python\helpers\pycharm\django_manage.py", line 46, in run_command
run_module(manage_file, None, '__main__', True)
File "C:\Users\OBUM\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 207, in run_module
return _run_module_code(code, init_globals, run_name, mod_spec)
File "C:\Users\OBUM\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 97, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "C:\Users\OBUM\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:/Users/OBUM/PycharmProjects/newproject\manage.py", line 21, in <module>
main()
File "C:/Users/OBUM/PycharmProjects/newproject\manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "C:\Users\OBUM\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "C:\Users\OBUM\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\management\__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\OBUM\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\management\base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\OBUM\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\management\commands\runserver.py", line 60, in execute
super().execute(*args, **options)
File "C:\Users\OBUM\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\management\base.py", line 364, in execute
output = self.handle(*args, **options)
File "C:\Users\OBUM\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\management\commands\runserver.py", line 67, in handle
if not settings.DEBUG and not settings.ALLOWED_HOSTS:
File "C:\Users\OBUM\AppData\Local\Programs\Python\Python38\lib\site-packages\django\conf\__init__.py", line 79, in __getattr__
self._setup(name)
File "C:\Users\OBUM\AppData\Local\Programs\Python\Python38\lib\site-packages\django\conf\__init__.py", line 60, in _setup
raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: Requested setting DEBUG, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
Can someone help me please

that will happen sometimes when your trying to run your app with 'run' icon (green triangle).
try this command in the terminal :
python manage.py runserver

Related

Upgrade geodjango app to django1.9

I am trying to upgrade my django project from django1.8.8 to django1.9.2
Right now I encounter a problem when running my tests with django1.9.2:
python manage.py test
This gives me the following error
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_from_command_line(sys.argv)
File "/home/ilse/myvenv/lib/python3.4/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/home/ilse/myvenv/lib/python3.4/site-packages/django/core/management/__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/ilse/myvenv/lib/python3.4/site-packages/django/core/management/commands/test.py", line 30, in run_from_argv
super(Command, self).run_from_argv(argv)
File "/home/ilse/myvenv/lib/python3.4/site-packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/ilse/myvenv/lib/python3.4/site-packages/django/core/management/commands/test.py", line 74, in execute
super(Command, self).execute(*args, **options)
File "/home/ilse/myvenv/lib/python3.4/site-packages/django/core/management/base.py", line 399, in execute
output = self.handle(*args, **options)
File "/home/ilse/myvenv/lib/python3.4/site-packages/django/core/management/commands/test.py", line 90, in handle
failures = test_runner.run_tests(test_labels)
File "/home/ilse/myvenv/lib/python3.4/site-packages/django/test/runner.py", line 532, in run_tests
old_config = self.setup_databases()
File "/home/ilse/myvenv/lib/python3.4/site-packages/django/test/runner.py", line 482, in setup_databases
self.parallel, **kwargs
File "/home/ilse/myvenv/lib/python3.4/site-packages/django/test/runner.py", line 726, in setup_databases
serialize=connection.settings_dict.get("TEST", {}).get("SERIALIZE", True),
File "/home/ilse/myvenv/lib/python3.4/site-packages/django/db/backends/base/creation.py", line 70, in create_test_db
run_syncdb=True,
File "/home/ilse/myvenv/lib/python3.4/site-packages/django/core/management/__init__.py", line 119, in call_command
return command.execute(*args, **defaults)
File "/home/ilse/myvenv/lib/python3.4/site-packages/django/core/management/base.py", line 399, in execute
output = self.handle(*args, **options)
File "/home/ilse/myvenv/lib/python3.4/site-packages/django/core/management/commands/migrate.py", line 87, in handle
connection.prepare_database()
File "/home/ilse/myvenv/lib/python3.4/site-packages/django/contrib/gis/db/backends/postgis/base.py", line 25, in prepare_database
cursor.execute("CREATE EXTENSION IF NOT EXISTS postgis")
File "/home/ilse/myvenv/lib/python3.4/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/home/ilse/myvenv/lib/python3.4/site-packages/django/db/utils.py", line 95, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/ilse/myvenv/lib/python3.4/site-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/home/ilse/myvenv/lib/python3.4/site-packages/django/db/backends/utils.py", line 62, in execute
return self.cursor.execute(sql)
django.db.utils.InternalError: PostGIS is already installed in schema 'public', uninstall it first
In django1.8 everything works as expected.
Are there any changes in django1.9 and postgis I am not aware of?
It may be due to postgis. Please make sure postgres have the postgis extension.
I could solve this by a hard reset of the databse.

Testing Django in a Virtual Environment

I have a Django project setup under virtualenv, and have a empty tests.py under the project folder.
When I do "python manage.py test", I am getting the following error:
Traceback (most recent call last):
File "manage.py", line 12, in <module>
execute_from_command_line(sys.argv)
File "/Users/dj_prj/dj_prj/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/Users/dj_prj/dj_prj/env/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/dj_prj/dj_prj/env/lib/python2.7/site-packages/django/core/management/commands/test.py", line 50, in run_from_argv
super(Command, self).run_from_argv(argv)
File "/Users/dj_prj/dj_prj/env/lib/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Users/dj_prj/dj_prj/env/lib/python2.7/site-packages/django/core/management/commands/test.py", line 71, in execute
super(Command, self).execute(*args, **options)
File "/Users/dj_prj/dj_prj/env/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/Users/dj_prj/dj_prj/env/lib/python2.7/site-packages/django/core/management/commands/test.py", line 88, in handle
failures = test_runner.run_tests(test_labels)
File "/Users/dj_prj/dj_prj/oicms/test/oicms_test_runner.py", line 209, in run_tests
suite = self.build_suite(test_labels, extra_tests)
File "/Users/dj_prj/dj_prj/oicms/test/oicms_test_runner.py", line 150, in build_suite
tests = self.test_loader.discover(start_dir=label, **kwargs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/loader.py", line 206, in discover
tests = list(self._find_tests(start_dir, pattern))
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/loader.py", line 267, in _find_tests
raise ImportError(msg % (mod_name, module_dir, expected_dir))
ImportError: 'tests' module incorrectly imported from '/Users/dj_prj/dj_prj/dj_prj'. Expected '/Users/dj_prj/dj_prj/'. Is this module globally installed?
What is your environment?
Your problem may be related to this one:
Django test runner fails in virtualenv on Ubuntu

API Test Case - 'module' object has no attribute

$ python manage.py test homepage.shortlistedlist
When i run above django rest framework testcase file, i met below error, kindly help me to solve this problem,
(py3.4)testuser#testuser-To:~/projects/testfile/testfile$ python manage.py test homepage.compareproperties --settings=testfile.settings.test
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/testuser/envs/testfile/lib/python3.4/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/home/testuser/envs/testfile/lib/python3.4/site-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/testuser/envs/testfile/lib/python3.4/site-packages/django/core/management/commands/test.py", line 50, in run_from_argv
super(Command, self).run_from_argv(argv)
File "/home/testuser/envs/testfile/lib/python3.4/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/testuser/envs/testfile/lib/python3.4/site-packages/django/core/management/commands/test.py", line 71, in execute
super(Command, self).execute(*args, **options)
File "/home/testuser/envs/testfile/lib/python3.4/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/home/testuser/envs/testfile/lib/python3.4/site-packages/django/core/management/commands/test.py", line 88, in handle
failures = test_runner.run_tests(test_labels)
File "/home/testuser/envs/testfile/lib/python3.4/site-packages/django/test/runner.py", line 146, in run_tests
suite = self.build_suite(test_labels, extra_tests)
File "/home/testuser/envs/testfile/lib/python3.4/site-packages/django/test/runner.py", line 95, in build_suite
tests = self.test_loader.discover(start_dir=label, **kwargs)
File "/usr/lib/python3.4/unittest/loader.py", line 255, in discover
self._get_directory_containing_module(top_part)
File "/usr/lib/python3.4/unittest/loader.py", line 269, in _get_directory_containing_module
full_path = os.path.abspath(module.__file__)
AttributeError: 'module' object has no attribute '__file__'
Thanks In Advance,
I was able to solve this by adding an empty __init__.py to the root of my project.
I think the clue is the get_directory_containing_module() call - without __init__.py, it doesn't see the directory as a module.

Django-jython war file deployment

Trying to create a war file from my django program, keep running into this error when running jython manage.py war:
jython manage.py war --include-java-libs "/home/user/Downloads/mysql-connector-java-5.1.18/mysql-connector-java-5.1.18-bin.jar"
Traceback (most recent call last):
File "manage.py", line 14, in <module>
execute_manager(settings)
File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 219, in execute
self.validate()
File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 219, in execute
self.validate()
File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 249, in validate
num_errors = get_validation_errors(s, app)
File "/usr/lib/python2.7/site-packages/django/core/management/validation.py", line 28, in get_validation_errors
from django.db import models, connection
File "/usr/lib/python2.7/site-packages/django/db/__init__.py", line 78, in <module>
connection = connections[DEFAULT_DB_ALIAS]
File "/usr/lib/python2.7/site-packages/django/db/utils.py", line 94, in __getitem__
conn = backend.DatabaseWrapper(db, alias)
File "/usr/lib/python2.7/site-packages/doj/backends/zxjdbc/mysql/base.py", line 152, in __init__
self.features = DatabaseFeatures()
TypeError: __init__() takes exactly 2 arguments (1 given)
Any help would be greatly appreciated!
Appears to be a known bug, hopefully taken care of soon.
http://code.google.com/p/django-jython/issues/detail?id=56&q=mysql

Haystack + Whoosh IndexError: Index was created on an architecture with different data sizes

When rebuilding my indices via ./manage.py rebuild_index I get this error:
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_manager(settings)
File "/Library/Python/2.6/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/Library/Python/2.6/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Python/2.6/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Library/Python/2.6/site-packages/django/core/management/base.py", line 218, in execute
output = self.handle(*args, **options)
File "/Library/Python/2.6/site-packages/haystack/management/commands/rebuild_index.py", line 13, in handle
call_command('clear_index', **options)
File "/Library/Python/2.6/site-packages/django/core/management/__init__.py", line 166, in call_command
return klass.execute(*args, **defaults)
File "/Library/Python/2.6/site-packages/django/core/management/base.py", line 218, in execute
output = self.handle(*args, **options)
File "/Library/Python/2.6/site-packages/haystack/management/commands/clear_index.py", line 38, in handle
sb.clear()
File "/Library/Python/2.6/site-packages/haystack/backends/whoosh_backend.py", line 197, in clear
self.setup()
File "/Library/Python/2.6/site-packages/haystack/backends/whoosh_backend.py", line 105, in setup
self.index = self.storage.open_index(schema=self.schema)
File "/Library/Python/2.6/site-packages/Whoosh-0.3.18-py2.6.egg/whoosh/filedb/filestore.py", line 48, in open_index
File "/Library/Python/2.6/site-packages/Whoosh-0.3.18-py2.6.egg/whoosh/filedb/fileindex.py", line 94, in __init__
File "/Library/Python/2.6/site-packages/Whoosh-0.3.18-py2.6.egg/whoosh/filedb/fileindex.py", line 173, in _read
IndexError: Index was created on an architecture with different data sizes
You have probably downgraded from whoosh 1.0.0 to 0.3.18, but there are some buggy index files already created at the path you defined by HAYSTACK_WHOOSH_PATH. Just make that directory empty and try again.