I am having this issue when I try to run the server in Pycharm. I am new to Django and downloaded this project as a backend for my react application. I have generated a Secret Key using:
from django.core.management.utils import get_random_secret_key
print(get_random_secret_key())
exit()
I added this Secret key to settings.py file as well.
Error Log which I get:
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
File "C:\Users\zabim\AppData\Local\Programs\Python\Python39\lib\threading.py", line 973, in _bootstrap_inner
self.run()
File "C:\Users\zabim\AppData\Local\Programs\Python\Python39\lib\threading.py", line 910, in run
self._target(*self._args, **self._kwargs)
File "W:\Playlistify-main\Playlistify-main\server\venv\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "W:\Playlistify-main\Playlistify-main\server\venv\lib\site-packages\django\core\management\commands\runserver.py", line 110, in inner_run
autoreload.raise_last_exception()
File "W:\Playlistify-main\Playlistify-main\server\venv\lib\site-packages\django\utils\autoreload.py", line 87, in raise_last_exception
raise _exception[1]
File "W:\Playlistify-main\Playlistify-main\server\venv\lib\site-packages\django\core\management\__init__.py", line 375, in execute
autoreload.check_errors(django.setup)()
File "W:\Playlistify-main\Playlistify-main\server\venv\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "W:\Playlistify-main\Playlistify-main\server\venv\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "W:\Playlistify-main\Playlistify-main\server\venv\lib\site-packages\django\apps\registry.py", line 122, in populate
app_config.ready()
File "W:\Playlistify-main\Playlistify-main\server\venv\lib\site-packages\django\contrib\admin\apps.py", line 27, in ready
self.module.autodiscover()
File "W:\Playlistify-main\Playlistify-main\server\venv\lib\site-packages\django\contrib\admin\__init__.py", line 24, in autodiscover
autodiscover_modules('admin', register_to=site)
File "W:\Playlistify-main\Playlistify-main\server\venv\lib\site-packages\django\utils\module_loading.py", line 47, in autodiscover_modules
import_module('%s.%s' % (app_config.name, module_to_search))
File "C:\Users\zabim\AppData\Local\Programs\Python\Python39\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "W:\Playlistify-main\Playlistify-main\server\venv\lib\site-packages\django\contrib\auth\admin.py", line 6, in <module>
from django.contrib.auth.forms import (
File "W:\Playlistify-main\Playlistify-main\server\venv\lib\site-packages\django\contrib\auth\forms.py", line 11, in <module>
from django.contrib.auth.tokens import default_token_generator
File "W:\Playlistify-main\Playlistify-main\server\venv\lib\site-packages\django\contrib\auth\tokens.py", line 117, in <module>
default_token_generator = PasswordResetTokenGenerator()
File "W:\Playlistify-main\Playlistify-main\server\venv\lib\site-packages\django\contrib\auth\tokens.py", line 18, in __init__
self.secret = self.secret or settings.SECRET_KEY
File "W:\Playlistify-main\Playlistify-main\server\venv\lib\site-packages\django\conf\__init__.py", line 90, in __getattr__
raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.
Go to your settings.py
SECRET_KEY = ""
There should already be a value, if not, copy paste the one from the print statement.
Have a look at the different module for the settings, you could have one for local, production and base for example, make sure all of them have a secret key.
Learn about secret key
This is very important to understand, I strongly advise to have a look at the Django Tutorial as this error should be obvious to most beginners in Django
Related
Please I'm trying to implement Django AMP in my site so According to the docs here https://django-amp-tools.readthedocs.io/en/latest/installation.html.
I have added the required to my settings.py but still getting this error below
(my_venv) ~/my_venv/amp $ python manage.py runserver
Watching for file changes with StatReloader Exception in thread django-main-thread:
Traceback (most recent call last): File "/data/data/com.termux/files/usr/lib/python3.11/threading.py", line 1038, in _bootstrap_inner
self.run() File "/data/data/com.termux/files/usr/lib/python3.11/threading.py", line 975, in run
self._target(*self._args, **self._kwargs)
File "/data/data/com.termux/files/home/my_venv/lib/python3.11/site-packages/django/utils/autoreload.py", line 64, in wrapper
fn(*args, **kwargs) File "/data/data/com.termux/files/home/my_venv/lib/python3.11/site-packages/django/core/management/commands/runserver.py", line 125, in inner_run
autoreload.raise_last_exception()
File "/data/data/com.termux/files/home/my_venv/lib/python3.11/site-packages/django/utils/autoreload.py", line 87, in raise_last_exception
raise _exception[1]
File "/data/data/com.termux/files/home/my_venv/lib/python3.11/site-packages/django/core/management/__init__.py", line 398, in execute
autoreload.check_errors(django.setup)()
File "/data/data/com.termux/files/home/my_venv/lib/python3.11/site-packages/django/utils/autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "/data/data/com.termux/files/home/my_venv/lib/python3.11/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/data/data/com.termux/files/home/my_venv/lib/python3.11/site-packages/django/apps/registry.py", line 91, in populate
app_config = AppConfig.create(entry)
^^^^^^^^^^^^^^^^^^^^^^^
File "/data/data/com.termux/files/home/my_venv/lib/python3.11/site-packages/django/apps/config.py", line 193, in create
import_module(entry)
File "/data/data/com.termux/files/usr/lib/python3.11/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 940, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/data/data/com.termux/files/home/my_venv/lib/python3.11/site-packages/amp_tools/__init__.py", line 4, in <module>
from amp_tools.settings import settings
File "/data/data/com.termux/files/home/my_venv/lib/python3.11/site-packages/amp_tools/settings.py", line 25, in <module>
class defaults(object):
File "/data/data/com.termux/files/home/my_venv/lib/python3.11/site-packages/amp_tools/settings.py", line 39, in defaults
TEMPLATES = django_settings.TEMPLATES[0]['OPTIONS']['loaders']
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^
KeyError: 'loaders'
So please how can I solve this error
I added amp_tools.loader.Loader as first item to my loaders list for TEMPLATES setting in settings.py.
but still this error still coming up, how can i implement django accelerated page on my site if this doesn't work well
Django errors when running via Virtual Environment: Exception in thread Django-main-thread. I am doing this in Venv and not sure where I am going wrong? Can someone please help?
Initially, I ran into this issue when I accidentally upgraded Django when PyCharm prompted it but after that, I created a Venv and moved my files over but the error seems to be persistent.
(venv) users-MacBook-Pro:myproject $ python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...
Exception in thread django-main-thread:
Traceback (most recent call last):
File "/Users/venv/lib/python3.7/site-packages/django/template/utils.py", line 66, in __getitem__
return self._engines[alias]
KeyError: 'django'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 926, in _bootstrap_inner
self.run()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "/Users/Documents/venv/lib/python3.7/site-packages/django/utils/autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "/Users/venv/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 117, in inner_run
self.check(display_num_errors=True)
File "/Users/venv/lib/python3.7/site-packages/django/core/management/base.py", line 390, in check
include_deployment_checks=include_deployment_checks,
File "/Users/venv/lib/python3.7/site-packages/django/core/management/base.py", line 377, in _run_checks
return checks.run_checks(**kwargs)
File "/Users/venv/lib/python3.7/site-packages/django/core/checks/registry.py", line 72, in run_checks
new_errors = check(app_configs=app_configs)
File "/Users/venv/lib/python3.7/site-packages/django/contrib/admin/checks.py", line 79, in check_dependencies
for engine in engines.all():
File "/Users/venv/lib/python3.7/site-packages/django/template/utils.py", line 90, in all
return [self[alias] for alias in self]
File "/Users/venv/lib/python3.7/site-packages/django/template/utils.py", line 90, in <listcomp>
return [self[alias] for alias in self]
File "/Users/venv/lib/python3.7/site-packages/django/template/utils.py", line 81, in __getitem__
engine = engine_cls(params)
File "/Users/Documents/venv/lib/python3.7/site-packages/django/template/backends/django.py", line 25, in __init__
options['libraries'] = self.get_templatetag_libraries(libraries)
File "/Users/venv/lib/python3.7/site-packages/django/template/backends/django.py", line 43, in get_templatetag_libraries
libraries = get_installed_libraries()
File "/Users/venv/lib/python3.7/site-packages/django/template/backends/django.py", line 108, in get_installed_libraries
for name in get_package_libraries(pkg):
File "/Users/venv/lib/python3.7/site-packages/django/template/backends/django.py", line 121, in get_package_libraries
module = import_module(entry[1])
File "/Users/venv/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/Users/venv/lib/python3.7/site-packages/rest_framework/templatetags/rest_framework.py", line 15, in <module>
from rest_framework.renderers import HTMLFormRenderer
File "/Users/venv/lib/python3.7/site-packages/rest_framework/renderers.py", line 20, in <module>
from django.test.client import encode_multipart
File "/Users/venv/lib/python3.7/site-packages/django/test/client.py", line 23, in <module>
from django.test import signals
File "<frozen importlib._bootstrap>", line 980, in _find_and_load
File "<frozen importlib._bootstrap>", line 149, in __enter__
File "<frozen importlib._bootstrap>", line 94, in acquire
_frozen_importlib._DeadlockError: deadlock detected by _ModuleLock('django.test.signals') at 4373516432
Error while executing python manage.py runserver
enter code here Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
File
"c:\users\hp\appdata\local\programs\python\python37\Lib\threading.py",
line 917, in _bootstrap_inner
self.run()
File "c:\users\hp\appdata\local\programs\python\python37\Lib\threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\HP\Desktop\iam_orm_layer\env\lib\site-packages\django\utils\autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "C:\Users\HP\Desktop\iam_orm_layer\env\lib\site-packages\django\core\management\commands\runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "C:\Users\HP\Desktop\iam_orm_layer\env\lib\site-packages\django\utils\autoreload.py", line 77, in raise_last_exception
raise _exception[1]
File "C:\Users\HP\Desktop\iam_orm_layer\env\lib\site-packages\django\core\management\__init__.py", line 337, in execute
autoreload.check_errors(django.setup)()
File "C:\Users\HP\Desktop\iam_orm_layer\env\lib\site-packages\django\utils\autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "C:\Users\HP\Desktop\iam_orm_layer\env\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\HP\Desktop\iam_orm_layer\env\lib\site-packages\django\apps\registry.py", line 91, in populate
app_config = AppConfig.create(entry)
File "C:\Users\HP\Desktop\iam_orm_layer\env\lib\site-packages\django\apps\config.py", line 90, in create
module = import_module(entry)
File "C:\Users\HP\Desktop\iam_orm_layer\env\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\HP\Desktop\iam_orm_layer\env\lib\site-packages\rest_framework_filters\__init__.py", line 3, in <module>
from .filterset import FilterSet
File "C:\Users\HP\Desktop\iam_orm_layer\env\lib\site-packages\rest_framework_filters\filterset.py", line 10, in <module>
from django_filters import filterset, rest_framework
File "C:\Users\HP\Desktop\iam_orm_layer\env\lib\site-packages\django_filters\__init__.py", line 7, in <module>
from .filterset import FilterSet
File "C:\Users\HP\Desktop\iam_orm_layer\env\lib\site-packages\django_filters\filterset.py", line 15, in <module>
from .filters import (
File "C:\Users\HP\Desktop\iam_orm_layer\env\lib\site-packages\django_filters\filters.py", line 10, in <module>
from django.db.models.sql.constants import QUERY_TERMS
ImportError: cannot import name 'QUERY_TERMS' from 'django.db.models.sql.constants' (C:\Users\HP\Desktop\iam_orm_layer\env\lib\site-packages\django\db\models\sql\constants.py)
Already answered here:
Could not import QUERY_TERMS
The constant you are trying to import does not exist in the django filters version you are using
I would like to enable my django-cms instance to host multiple sites.
For that I created two different sites in the admin panel.
Unfortunately only one site is shown because I needed to hardcode the SITE_ID in the project settings.
According to https://github.com/django/django/pull/2460 this is not a mandatory setting anymore. But my Django 1.10.7 instance shows the following traceback if I delete it:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/var/www/venv/lib/python3.5/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/var/www/venv/lib/python3.5/site-packages/django/core/management/__init__.py", line 312, in execute
django.setup()
File "/var/www/venv/lib/python3.5/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/var/www/venv/lib/python3.5/site-packages/django/apps/registry.py", line 115, in populate
app_config.ready()
File "/var/www/venv/lib/python3.5/site-packages/django/contrib/admin/apps.py", line 22, in ready
self.module.autodiscover()
File "/var/www/venv/lib/python3.5/site-packages/django/contrib/admin/__init__.py", line 24, in autodiscover
autodiscover_modules('admin', register_to=site)
File "/var/www/venv/lib/python3.5/site-packages/django/utils/module_loading.py", line 74, in autodiscover_modules
import_module('%s.%s' % (app_config.name, module_to_search))
File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 665, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "/var/www/venv/lib/python3.5/site-packages/cms/admin/__init__.py", line 2, in <module>
import cms.admin.pageadmin
File "/var/www/venv/lib/python3.5/site-packages/cms/admin/pageadmin.py", line 39, in <module>
from cms.admin.forms import (
File "/var/www/venv/lib/python3.5/site-packages/cms/admin/forms.py", line 85, in <module>
class PageForm(forms.ModelForm):
File "/var/www/venv/lib/python3.5/site-packages/cms/admin/forms.py", line 86, in PageForm
language = forms.ChoiceField(label=_("Language"), choices=get_language_tuple(),
File "/var/www/venv/lib/python3.5/site-packages/cms/utils/i18n.py", line 76, in get_language_tuple
return [(lang['code'], lang['name']) for lang in get_languages(site_id)]
File "/var/www/venv/lib/python3.5/site-packages/cms/utils/i18n.py", line 23, in get_languages
site_id = get_site_id(site_id)
File "/var/www/venv/lib/python3.5/site-packages/cms/utils/conf.py", line 294, in get_site_id
return settings.SITE_ID
File "/var/www/venv/lib/python3.5/site-packages/django/conf/__init__.py", line 49, in __getattr__
return getattr(self._wrapped, name)
AttributeError: 'Settings' object has no attribute 'SITE_ID'
Looks like SITE_ID is required by Django CMS, it's in the traceback
File "/var/www/venv/lib/python3.5/site-packages/cms/utils/conf.py", line 294, in get_site_id
return settings.SITE_ID
I solved to problem differently.
I used the plugin djangocms-multisite.
I don't know if it is the best solution but it works.
Ok when i'm in django I can run the website by the following command.
sudo python manage.py runserver
But when I try and use the greed arrow for running the project is gives me like a dozen errors.
This happens straight away when i set up the project and was hoping if anyone could help.
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x10484fbf8>
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/utils/autoreload.py", line 249, in raise_last_exception
six.reraise(*_exception)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/apps/registry.py", line 115, in populate
app_config.ready()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/contrib/admin/apps.py", line 22, in ready
self.module.autodiscover()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/contrib/admin/__init__.py", line 26, in autodiscover
autodiscover_modules('admin', register_to=site)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/utils/module_loading.py", line 50, in autodiscover_modules
import_module('%s.%s' % (app_config.name, module_to_search))
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 662, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/contrib/auth/admin.py", line 7, in <module>
from django.contrib.auth.forms import (
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/contrib/auth/forms.py", line 264, in <module>
class SetPasswordForm(forms.Form):
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/contrib/auth/forms.py", line 275, in SetPasswordForm
help_text=password_validation.password_validators_help_text_html())
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/contrib/auth/password_validation.py", line 85, in password_validators_help_text_html
help_texts = password_validators_help_texts(password_validators)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/contrib/auth/password_validation.py", line 74, in password_validators_help_texts
password_validators = get_default_password_validators()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/contrib/auth/password_validation.py", line 21, in get_default_password_validators
return get_password_validators(settings.AUTH_PASSWORD_VALIDATORS)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/contrib/auth/password_validation.py", line 32, in get_password_validators
validators.append(klass(**validator.get('OPTIONS', {})))
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/contrib/auth/password_validation.py", line 170, in __init__
common_passwords_lines = gzip.open(password_list_path).read().decode('utf-8').splitlines()
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 0: invalid start byte
I know…
I was getting a similar error for a different issue, but it turned out that it was a problem with the way PyCharm handled Unicode/UTF-8 with Python 3. I ended up doing the following to get the error to go away.
Add following line in the file "pycharm.exe.vmoptions":
-Dfile.encoding=UTF-8
Source:
Why unicode string is not shown on PyCharm's console?
Hope this helps!