Django-cms: 'Settings' object has no attribute 'SITE_ID' - django

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.

Related

Django gives Secret key must not be empty error

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

Django ImportError: No module named 'webapp_credentials'

I am running this code:
https://github.com/cndreisbach/call-for-service/blob/master/docs/src/development.md
When im running this part of code in my Vagrant shell :
python3 ./cfs/manage.py migrate --settings=cfs.settings.local
It's returning me that there is no "ImportError: No module named 'webapp_credentials'"
This is the error :
Traceback (most recent call last):
File "./cfs/manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.5/dist-packages/django/core/management/__init__.py", line 351, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.5/dist-packages/django/core/management/__init__.py", line 303, in execute
settings.INSTALLED_APPS
File "/usr/local/lib/python3.5/dist-packages/django/conf/__init__.py", line 48, in __getattr__
self._setup(name)
File "/usr/local/lib/python3.5/dist-packages/django/conf/__init__.py", line 44, in _setup
self._wrapped = Settings(settings_module)
File "/usr/local/lib/python3.5/dist-packages/django/conf/__init__.py", line 92, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
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 985, in _gcd_import
File "<frozen importlib._bootstrap>", line 968, in _find_and_load
File "<frozen importlib._bootstrap>", line 957, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 697, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "/vagrant/cfs/cfs/settings/local.py", line 1, in <module>
from .base import *
File "/vagrant/cfs/cfs/settings/base.py", line 15, in <module>
from webapp_credentials import creds
ImportError: No module named 'webapp_credentials'
Is webapp_credentials a module of python OS how do i fix this?
webapp_credentials.py is on .gitignore, that is why migrate can't find it.
You need this file, which is not versioned in this git repository of your link.

While giving the command - python manage.py runserver, it shows the given error

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

django enum field error when migrating

I'm using some enum fields in my data model. I've installed django-enumfield package. My django version is 1.10.6 and django-enumfield version is 1.2.1.
Anyway I get the following error when db migration is issued.
$ python manage.py makemigrations
Output:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.5/dist-packages/Django-1.10.6-py3.5.egg/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.5/dist-packages/Django-1.10.6-py3.5.egg/django/core/management/__init__.py", line 341, in execute
django.setup()
File "/usr/local/lib/python3.5/dist-packages/Django-1.10.6-py3.5.egg/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python3.5/dist-packages/Django-1.10.6-py3.5.egg/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/usr/local/lib/python3.5/dist-packages/Django-1.10.6-py3.5.egg/django/apps/config.py", line 199, in import_models
self.models_module = import_module(models_module_name)
File "/home/indikau/anaconda3/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
File "/home/indikau/workspace/hotel_manager/manager/models.py", line 4, in <module>
from django_enumfield import enum
File "/usr/local/lib/python3.5/dist-packages/django_enumfield/enum.py", line 6, in <module>
from django_enumfield.db.fields import EnumField
File "/usr/local/lib/python3.5/dist-packages/django_enumfield/db/fields.py", line 8, in <module>
class EnumField(six.with_metaclass(models.SubfieldBase, models.IntegerField)):
AttributeError: module 'django.db.models' has no attribute 'SubfieldBase'
Is there anyway to fix this problem?
Thanks.
SubfieldBase was deprecated since 1.8 and it's removed in 1.10.
There looks like a few solutions available here: https://github.com/5monkeys/django-enumfield/issues/39

Why import error while using django-templated-email?

I am trying to use BradWhittington Django-Templated-Email. I installed it, and added the following lines in the settings.py.
from templated_email.backends.vanilla_django import TemplateBackend
TEMPLATED_EMAIL_BACKEND = TemplateBackend
When I try to run the server, I get the import error. Even when I use
from templated_email import send_templated_mail
in the models.py I again get the import error. I am new to django, and I googled for the answer many times. But no luck. What am I missing? The 'Run' window on pycharm shows the following:
"C:\Program Files\JetBrains\PyCharm 4.0.4\bin\runnerw.exe" "E:\***\***\***\env1\Scripts\python.exe" "C:\Program Files\JetBrains\PyCharm 4.0.4\helpers\pycharm\django_manage.py" syncdb "E:/***/***/***/***"
Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm 4.0.4\helpers\pycharm\django_manage.py", line 41, in <module>
run_module(manage_file, None, '__main__', True)
File "C:\Python34\Lib\runpy.py", line 182, in run_module
return _run_module_code(code, init_globals, run_name, mod_spec)
File "C:\Python34\Lib\runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "C:\Python34\Lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "E:/***/***/***/***\manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "E:\***\***\***\env1\lib\site-packages\django\core\management\__init__.py", line 385, in execute_from_command_line
utility.execute()
File "E:\***\***\***\env1\lib\site-packages\django\core\management\__init__.py", line 345, in execute
settings.INSTALLED_APPS
File "E:\***\***\***\env1\lib\site-packages\django\conf\__init__.py", line 46, in __getattr__
self._setup(name)
File "E:\***\***\***\env1\lib\site-packages\django\conf\__init__.py", line 42, in _setup
self._wrapped = Settings(settings_module)
File "E:\***\***\***\env1\lib\site-packages\django\conf\__init__.py", line 94, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "E:\***\***\***\env1\lib\importlib\__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "E:/***/***/***/***\***\settings.py", line 17, in <module>
from templated_email.backends.vanilla_django import TemplateBackend
File "E:\***\***\***\env1\lib\site-packages\templated_email\__init__.py", line 23
except ImportError, e:
^
SyntaxError: invalid syntax
Process finished with exit code 1
I am using virtual environment. Please help me.
Django-Templated-Email does not support python 3, which you are using.
You can migrate your project to python2, but it's better to find modern alternative to Django-Templated-Email.