Error importing "openwisp_utils.admin import ReadOnlyAdmin" - django

I am trying to implement django-freeradius, but I get the error cannot import name 'ReadOnlyAdmin', when I write the line * in urlspatters within urls.py of my project. I have tried to use the same configuration in https://github.com/openwisp/django-freeradius/blob/master/tests/urls.py, but it does not work.
# myproject/urls.py
from django.contrib import admin
from django.urls import path, include
from openwisp_utils.admin_theme.admin import admin, openwisp_admin
openwisp_admin()
admin.autodiscover()
urlpatterns = [
url(r'^', include('django_freeradius.urls', namespace='freeradius')), #* This line
path('admin/', admin.site.urls),
]
I have installed:
Python 3.6.8
Django 2.2.4
django-filter 2.1.0
django-freeradius 0.1a0
openwisp-utils 0.2.2
These are my apps in settings.py
# myproject/settings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_freeradius',
'django_filters',
]
And, this is the complete error when I run python manage.py runserver ()
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
self.run()
File "/usr/lib/python3.6/threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "/mnt/c/Users/myuser/Documents/python/hotspot/env/lib/python3.6/site-packages/django/utils/autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "/mnt/c/Users/myuser/Documents/python/hotspot/env/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "/mnt/c/Users/myuser/Documents/python/hotspot/env/lib/python3.6/site-packages/django/utils/autoreload.py", line 77, in raise_last_exception
raise _exception[1]
File "/mnt/c/Users/myuser/Documents/python/hotspot/env/lib/python3.6/site-packages/django/core/management/__init__.py", line 337, in execute
autoreload.check_errors(django.setup)()
File "/mnt/c/Users/myuser/Documents/python/hotspot/env/lib/python3.6/site-packages/django/utils/autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "/mnt/c/Users/myuser/Documents/python/hotspot/env/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/mnt/c/Users/myuser/Documents/python/hotspot/env/lib/python3.6/site-packages/django/apps/registry.py", line 122, in populate
app_config.ready()
File "/mnt/c/Users/myuser/Documents/python/hotspot/env/lib/python3.6/site-packages/django/contrib/admin/apps.py", line 24, in ready
self.module.autodiscover()
File "/mnt/c/Users/myuser/Documents/python/hotspot/env/lib/python3.6/site-packages/django/contrib/admin/__init__.py", line 26, in autodiscover
autodiscover_modules('admin', register_to=site)
File "/mnt/c/Users/myuser/Documents/python/hotspot/env/lib/python3.6/site-packages/django/utils/module_loading.py", line 47, in autodiscover_modules
import_module('%s.%s' % (app_config.name, module_to_search))
File "/mnt/c/Users/myuser/Documents/python/hotspot/env/lib/python3.6/importlib/__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/mnt/c/Users/myuser/Documents/python/hotspot/env/src/django-freeradius/django_freeradius/admin.py", line 6, in <module>
from .base.admin import (
File "/mnt/c/Users/myuser/Documents/python/hotspot/env/src/django-freeradius/django_freeradius/base/admin.py", line 9, in <module>
from openwisp_utils.admin import ReadOnlyAdmin, TimeReadonlyAdminMixin
ImportError: cannot import name 'ReadOnlyAdmin'
I appreciate if someone could give me the reason of this error.

Try to install the development version of openwisp-utils:
pip install --upgrade http://github.com/openwisp/openwisp-utils/tarball/master

Related

how to fix this error: No module named 'allauth'?

I want to use allauth in django API but when I installed it I got some errors I fixed it by django.setup() and after that, I get the error which tells me that I have to set DJANGO_SETTINGS_MODULE now I did that in manage.py:
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
import django
def main():
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'website.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
os.environ['DJANGO_SETTINGS_MODULE'] = 'website.settings'
django.setup()
main()
but I get this Traceback:
Traceback (most recent call last):
File "manage.py", line 23, in <module>
django.setup()
File "/home/abdelhamedabdin/.local/lib/python3.8/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/abdelhamedabdin/.local/lib/python3.8/site-packages/django/apps/registry.py", line 91, in populate
app_config = AppConfig.create(entry)
File "/home/abdelhamedabdin/.local/lib/python3.8/site-packages/django/apps/config.py", line 90, in create
module = import_module(entry)
File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'allauth'
please can anyone tells me how can I fix that exception error? I did many searches but I get no help and I asked here but also I got no help so, please if anyone can help me!
Additional information:
that is what I did in settings.py after I installed allauth by pip3
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.sites',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.account.auth_backends.AuthenticationBackend',
'index.apps.IndexConfig',
'account.apps.AccountConfig',
'community.apps.CommunityConfig',
]
AUTHENTICATION_BACKENDS = (
"django.contrib.auth.backends.ModelBackend",
"allauth.account.auth_backends.AuthenticationBackend",
)
SITE_ID = 1
and in urls.py
path('accounts/', include('allauth.urls')),
Edit post:
by using virtualenv that Trace has raised:
Traceback (most recent call last):
File "manage.py", line 23, in <module>
django.setup()
File "/media/abdelhamedabdin/BE4C6BE74C6B98C3/Cources/Django/all git/ripo/website/venv/lib/python3.8/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/media/abdelhamedabdin/BE4C6BE74C6B98C3/Cources/Django/all git/ripo/website/venv/lib/python3.8/site-packages/django/apps/registry.py", line 91, in populate
app_config = AppConfig.create(entry)
File "/media/abdelhamedabdin/BE4C6BE74C6B98C3/Cources/Django/all git/ripo/website/venv/lib/python3.8/site-packages/django/apps/config.py", line 90, in create
module = import_module(entry)
File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/media/abdelhamedabdin/BE4C6BE74C6B98C3/Cources/Django/all git/ripo/website/venv/lib/python3.8/site-packages/allauth/account/auth_backends.py", line 3, in <module>
from django.contrib.auth.backends import ModelBackend
File "/media/abdelhamedabdin/BE4C6BE74C6B98C3/Cources/Django/all git/ripo/website/venv/lib/python3.8/site-packages/django/contrib/auth/backends.py", line 5, in <module>
from django.contrib.auth.models import Permission
File "/media/abdelhamedabdin/BE4C6BE74C6B98C3/Cources/Django/all git/ripo/website/venv/lib/python3.8/site-packages/django/contrib/auth/models.py", line 2, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/media/abdelhamedabdin/BE4C6BE74C6B98C3/Cources/Django/all git/ripo/website/venv/lib/python3.8/site-packages/django/contrib/auth/base_user.py", line 47, in <module>
class AbstractBaseUser(models.Model):
File "/media/abdelhamedabdin/BE4C6BE74C6B98C3/Cources/Django/all git/ripo/website/venv/lib/python3.8/site-packages/django/db/models/base.py", line 107, in __new__
app_config = apps.get_containing_app_config(module)
File "/media/abdelhamedabdin/BE4C6BE74C6B98C3/Cources/Django/all git/ripo/website/venv/lib/python3.8/site-packages/django/apps/registry.py", line 252, in get_containing_app_config
self.check_apps_ready()
File "/media/abdelhamedabdin/BE4C6BE74C6B98C3/Cources/Django/all git/ripo/website/venv/lib/python3.8/site-packages/django/apps/registry.py", line 135, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
By installing django-allauth as follows:
python -m pip install django-allauth
I solved my problem and the main problem was spin around allauth.account that I want to migrate it into INSTALLED_APPS also, I had an additional app in this case, 'allauth.account.auth_backends.AuthenticationBackend', those apps was the reason for the problems.
for the first app (allauth.account.auth_backends.AuthenticationBackend)I was getting an error that tells me that I am not able to migrate the INSTALLED_APPS without migrating allauth app first.
for the second app (allauth.account) I was getting an error duplicate 'account' because I have already application with that name so, I had to rename the app name which already exists to name like accounts for example until I can install allauth.account succeeded.
until I am able to specify one error of each app I was migrating each one separately to show the specific error to it but when I was migrating the both together I was getting that Traceback I specified above.

ImportError: cannot import name 'python_2_unicode_compatible' when running migrations for Django-Invitations

First, I might want to mention I'm a beginner with Django. I'm trying to install Django-Invitations on my app to send sign up invitations. I followed their README instructions.
pip install django-invitations
# Add to settings.py, INSTALLED_APPS
'invitations',
# Append to urls.py
url(r'^invitations/', include('invitations.urls', namespace='invitations')),
# Run migrations
python manage.py migrate
I also pip installed all the requirements from their requirements file:
coverage==4.5.4
flake8==3.7.9
freezegun==0.3.12
mock==3.0.5
pytest==5.2.2
pytest-django==3.6.0
pytest-cov==2.8.1
tox==3.14.0
But I keep getting the same error when I run migrations for the first time:
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "C:\Users\maxim\Desktop\Web Development\Projects\admin\RentQ3\myEnv\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "C:\Users\maxim\Desktop\Web Development\Projects\admin\RentQ3\myEnv\lib\site-packages\django\core\management\__init__.py", line 377, in execute
django.setup()
File "C:\Users\maxim\Desktop\Web Development\Projects\admin\RentQ3\myEnv\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\maxim\Desktop\Web Development\Projects\admin\RentQ3\myEnv\lib\site-packages\django\apps\registry.py", line 114, in populate
app_config.import_models()
File "C:\Users\maxim\Desktop\Web Development\Projects\admin\RentQ3\myEnv\lib\site-packages\django\apps\config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "C:\Users\maxim\AppData\Local\Programs\Python\Python36-32\lib\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 "C:\Users\maxim\Desktop\Web Development\Projects\admin\RentQ3\myEnv\lib\site-packages\invitations\models.py", line 12, in <module>
from django.utils.encoding import python_2_unicode_compatible
ImportError: cannot import name 'python_2_unicode_compatible'
Any idea what the issue might be?
Thanks!
It should work if you install six.
All you then need to do is replace django.utils.encoding with six in your models.py.

Issue upgrading to Wagtail 2.1

Upgraded from Wagtail 2.0 to 2.1. Running on an Ubuntu vagrant box.
I get the error below when running any manage.py command after upgrading from Wagtail 2.0 to 2.1 or 2.11. If I downgrade back to 2.0 it works again, so I'm sure I have some incorrect dependencies in there...
Any thoughts on how to resolve this?
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/chrisrogers/blog/lib/python3.6/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
utility.execute()
File "/Users/chrisrogers/blog/lib/python3.6/site-packages/django/core/management/__init__.py", line 347, in execute
django.setup()
File "/Users/chrisrogers/blog/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/chrisrogers/blog/lib/python3.6/site-packages/django/apps/registry.py", line 89, in populate
app_config = AppConfig.create(entry)
File "/Users/chrisrogers/blog/lib/python3.6/site-packages/django/apps/config.py", line 116, in create
mod = import_module(mod_path)
File "/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/Users/chrisrogers/blog/lib/python3.6/site-packages/wagtail/search/apps.py", line 4, in <module>
from wagtail.search.signal_handlers import register_signal_handlers
File "/Users/chrisrogers/blog/lib/python3.6/site-packages/wagtail/search/signal_handlers.py", line 3, in <module>
from wagtail.search import index
File "/Users/chrisrogers/blog/lib/python3.6/site-packages/wagtail/search/index.py", line 10, in <module>
from modelcluster.fields import ParentalManyToManyField
File "/Users/chrisrogers/blog/lib/python3.6/site-packages/modelcluster/fields.py", line 19, in <module>
from modelcluster.models import get_related_model, ClusterableModel
File "/Users/chrisrogers/blog/lib/python3.6/site-packages/modelcluster/models.py", line 152, in <module>
class ClusterableModel(models.Model):
File "/Users/chrisrogers/blog/lib/python3.6/site-packages/django/db/models/base.py", line 100, in __new__
app_config = apps.get_containing_app_config(module)
File "/Users/chrisrogers/blog/lib/python3.6/site-packages/django/apps/registry.py", line 244, in get_containing_app_config
self.check_apps_ready()
File "/Users/chrisrogers/blog/lib/python3.6/site-packages/django/apps/registry.py", line 127, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
My req.txt is below:
Django==2.0
Jinja2==2.8
Markdown==2.6.2
MarkupSafe==0.23
Pillow>2.8.2
PyYAML==3.11
Pygments==2.0.2
Unidecode==0.04.18
Willow>0.2.2
ansible==2.0.1.0
beautifulsoup4==4.4.0
django-appconf==1.0.1
django-compressor==1.5
django-medusa==0.3.0
django-modelcluster==1.1
django-sendfile==0.3.10
django-taggit==0.18.0
django-treebeard==3.0
djangorestframework==3.7
ecdsa==0.13
elasticsearch==1.7.0
google-api-python-client==1.5.0
html5lib==0.999
httplib2==0.9.2
oauth2client==2
paramiko==1.16.0
postgres==2.1.2
psycopg2-binary==2.7.4
wagalytics==0.7
wagtail==2.1
wagtailfontawesome==1.1.3
wheel==0.24.0
You should upgrade django-modelcluster.
pip install django-modelcluster==4.1

ImportError: No module named 'wagtail.core'

I am using python3 in a virtual environment and have wagtail installed via pip. When I am trying to extend home model for home page. I get the error:-
ImportError: No module named 'wagtail.core'
Here is the code of models.py:-
from django.db import models
from wagtail.core.models import Page
from wagtail.core.fields import RichTextField
from wagtail.admin.edit_handlers import FieldPanel
class HomePage(Page):
body = RichTextField(blank=True)
content_panels = Page.content_panels + [
FieldPanel('body', classname="full"),
]
Here is the error stack:-
*Unhandled exception in thread started by <function check_errors
<locals>.wrapper at 0x7f8a45e44400>
Traceback (most recent call last):
File "/project/venv/lib/python3.4/site-packages/django/utils/autoreload.py", line 228, in wrapper fn(*args, **kwargs)
File "/project/venv/lib/python3.4/site-packages/django/core/management/commands/runserver.py", line 117, in inner_run autoreload.raise_last_exception()
File "/project/venv/lib/python3.4/site-packages/django/utils/autoreload.py", line 251, in raise_last_exception six.reraise(*_exception)
File "/project/venv/lib/python3.4/site-packages/django/utils/six.py", line 685, in reraise raise value.with_traceback(tb)
File "/project/venv/lib/python3.4/site-packages/django/utils/autoreload.py", line 228, in wrapper fn(*args, **kwargs)
File "/project/venv/lib/python3.4/site-packages/django/__init__.py", line 27, in setup apps.populate(settings.INSTALLED_APPS)
File "/project/venv/lib/python3.4/site-packages/django/apps/registry.py", line 108, in populate app_config.import_models()
File "/project/venv/lib/python3.4/site-packages/django/apps/config.py", line 202, in import_models self.models_module = import_module(models_module_name)
File "/project/venv/lib/python3.4/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 "/project/home/models.py", line 3, in <module> from wagtail.core.models import Page ImportError: No module named 'wagtail.core'*
I am following the basic tutorial for wagtail. Here is the link http://docs.wagtail.io/en/latest/getting_started/tutorial.html
Version of wagtail==1.13.1 and Django==1.11.10. Kindly point to right direction. Thanks in advance.
Edited.
You wrote import statements for wagtail 2.x.
Replace import statements with following statements which is for wagtail 1.13.1:
from wagtail.wagtailcore.models import Page
from wagtail.wagtailcore.fields import RichTextField
from wagtail.wagtailadmin.edit_handlers import FieldPanel
Kindly follow this link
http://docs.wagtail.io/en/v1.13.1/getting_started/tutorial.html

python + SQL db runserver ERROR

Django runserver is not work
python + SQL db. If I install sudo apt-get install python-mysqldb. Make migrate is okey, tables is create but runserver ERROR
Failed to get real commands on module "mysite": python process died with code 1: Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/django/db/backends/mysql/base.py", line 25, in <module>
import MySQLdb as Database
ImportError: No module named 'MySQLdb'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/ivan/pycharm-2016.3.2/helpers/pycharm/_jb_manage_tasks_provider.py", line 25, in <module>
django.setup()
File "/usr/local/lib/python3.5/dist-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python3.5/dist-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/usr/local/lib/python3.5/dist-packages/django/apps/config.py", line 199, in import_models
self.models_module = import_module(models_module_name)
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 "/usr/local/lib/python3.5/dist-packages/django/contrib/auth/models.py", line 4, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/usr/local/lib/python3.5/dist-packages/django/contrib/auth/base_user.py", line 52, in <module>
class AbstractBaseUser(models.Model):
File "/usr/local/lib/python3.5/dist-packages/django/db/models/base.py", line 119, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
Make sure you have PyMySQL module installed, if not use this.
pip install pymysql
In settings.py, add following code just below import os.
Your current code
import os
Your new code
import os
try:
import pymysql
pymysql.install_as_MySQLdb()
except:
pass