ImportError: No module named 'wagtail.core' - django

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

Related

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

TypeError: 'MediaDefiningClass' object is not iterable

I'm attempting to implement django-progressbarupload.
https://github.com/ouhouhsami/django-progressbarupload
I'm getting the following error:
for model in model_or_iterable:
TypeError: 'MediaDefiningClass' object is not iterable
admin.py
from django.contrib import admin
from accounts.models import UserProfile
class UserProfile(admin.ModelAdmin):
change_form_template = 'progressbarupload/change_form.html'
add_form_template = 'progressbarupload/change_form.html'
admin.site.register(UserProfile)
This is the traceback
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\jason\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\__init__.py", line 371, in execute_from_command_line
utility.execute()
File "C:\Users\jason\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\__init__.py", line 347, in execute
django.setup()
File "C:\Users\jason\AppData\Local\Programs\Python\Python36\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\jason\AppData\Local\Programs\Python\Python36\lib\site-packages\django\apps\registry.py", line 120, in populate
app_config.ready()
File "C:\Users\jason\AppData\Local\Programs\Python\Python36\lib\site-packages\django\contrib\admin\apps.py", line 23, in ready
self.module.autodiscover()
File "C:\Users\jason\AppData\Local\Programs\Python\Python36\lib\site-packages\django\contrib\admin\__init__.py", line 26, in autodiscover
autodiscover_modules('admin', register_to=site)
File "C:\Users\jason\AppData\Local\Programs\Python\Python36\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\jason\AppData\Local\Programs\Python\Python36\lib\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 "C:\Users\jason\Desktop\jason3\accounts\admin.py", line 18, in <module>
admin.site.register(UserProfile)
File "C:\Users\jason\AppData\Local\Programs\Python\Python36\lib\site-packages\django\contrib\admin\sites.py", line 102, in register
for model in model_or_iterable:
TypeError: 'MediaDefiningClass' object is not iterable
Thanks for the help!
The first parameter to register is the model class itself. You have used the same name for your model class as your admin class. Give them separate names and pass them both to register.
class UserProfileAdmin(admin.ModelAdmin):
change_form_template = 'progressbarupload/change_form.html'
add_form_template = 'progressbarupload/change_form.html'
admin.site.register(UserProfile, UserProfileAdmin)

AttributeError when I import model from another app

I don't know why but I got an error: AttributeError: module 'downloads.models' has no attribute 'AbstractDownload' in this place: class Download(models_downloads.AbstractDownload):
In download app I have already AbstractDownload class
Here is my model from products
products/models.py
from downloads import models as models_downloads
class Download(models_downloads.AbstractDownload):
product = models.ForeignKey('products.Product', related_name='downloads')
file = FilerFileField(related_name="file_products_download")
Here is downloads models
downloads/models.py
class AbstractDownload(models.Model):
title = models.CharField(max_length=500)
subtitle = models.CharField(max_length=1000, blank=True)
file = FilerFileField(related_name="file_abstract_download")
order = models.PositiveIntegerField(default=0)
class Meta:
abstract = True
def __str__(self):
return self.title
Traceback:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/path/venv/lib/python3.5/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
utility.execute()
File "/path/venv/lib/python3.5/site-packages/django/core/management/__init__.py", line 337, in execute
django.setup()
File "/path/venv/lib/python3.5/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/path/venv/lib/python3.5/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models()
File "/path/venv/lib/python3.5/site-packages/django/apps/config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "/path/venv/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 "/path/www/downloads/models.py", line 6, in <module>
from products import models as products_models
File "/path/www/products/models.py", line 31, in <module>
class Download(models_downloads.AbstractDownload):
AttributeError: module 'downloads.models' has no attribute 'AbstractDownload'
You have a circular import. Your downloads/models.py has:
from products import models as products_models
But your products/models.py has
from downloads import models as models_downloads
You haven't shown how you use products_models, so we can't really say how to fix it. Here's a few suggestions:
Perhaps that import isn't necessary if you use a string for foreign keys, e.g. models.ForeignKey('downloads.ModelName')
Perhaps you could move AbstractDownload and Download so that they are in the same models, so that you don't need an import
If you use products_models inside a method, you could move the import inside the method. I would avoid this if possible.

Django has no attribute 'GeoManager' issue

from django.db import models
from django.contrib.gis.db import models
location = models.PointField(srid=4326,null=True,blank=True)
objects = models.GeoManager()
I am hosting my Django project on AWS server. I am unable to run the project because of the error I added below, but I implemented the same project in my Ubuntu system and it's working fine.
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7f527104b6a8> Traceback (most recent call last): File "/home/ubuntu/django_env/lib/python3.5/site-packages/django/utils/autoreload.py", line 225, in wrapper fn(*args, **kwargs) File "/home/ubuntu/django_env/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 112, in inner_run autoreload.raise_last_exception() File "/home/ubuntu/django_env/lib/python3.5/site-packages/django/utils/autoreload.py", line 248, in raise_last_exception raise _exception[1] File "/home/ubuntu/django_env/lib/python3.5/site-packages/django/core/management/__init__.py", line 327, in execute autoreload.check_errors(django.setup)() File "/home/ubuntu/django_env/lib/python3.5/site-packages/django/utils/autoreload.py", line 225, in wrapper fn(*args, **kwargs) File "/home/ubuntu/django_env/lib/python3.5/site-packages/django/__init__.py", line 24, in setup apps.populate(settings.INSTALLED_APPS) File "/home/ubuntu/django_env/lib/python3.5/site-packages/django/apps/registry.py", line 112, in populate app_config.import_models() File "/home/ubuntu/django_env/lib/python3.5/site-packages/django/apps/config.py", line 198, in import_models self.models_module = import_module(models_module_name) File "/home/ubuntu/django_env/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 "/home/ubuntu/Sg_Bus/SgBusTransport/models.py", line 10, in <module> class BusStop(models.Model): File "/home/ubuntu/Sg_Bus/SgBusTransport/models.py", line 17, in BusStop objects = models.GeoManager() AttributeError: module 'django.contrib.gis.db.models' has no attribute 'GeoManager'
Is it possible that you are running Django 2.0?
GeoManager has been removed.
A workaround that appears to function correctly as of Django 2.0:
Import in your models file:
from django.db.models import Manager as GeoManager
In your model class:
objects = GeoManager()
Now you should be able to do spatial lookups!
Credit to this django-cities pull request.
You could try:
from django.contrib.gis.db.models.manager import GeoManager
Also you'll want to avoid situations like this
from django.db import models
from django.contrib.gis.db import models
The problem is this, you've imported two models modules - which one does Python use when you try to use models.Whatever?
Try something like this:
from django.db import models
from django.contrib.gis.db import models as gis_models
Instead of GeoManager you can now just use Manager
from django.db.models.manager import Manager

PointField() Not Working correctly in GeoDjango

I have GDAL (using homebrew) and SQLite installed. I would like to create a teacher with a PointField() which stores long and lat values, to know their location. Later I plan on adding the ability to search by distance using something like:
Teacher.objects.filter(location__distance_lte=(your_location,D(m=distance))).distance(your_location).order_by('distance')
models.py
from django.db import models
from django.contrib.gis.db import models as gis_models
from django.contrib.auth.models import User
class Teacher(models.Model):
user = models.ForeignKey(User, unique=True)
location = gis_models.PointField()
availability = models.BooleanField(default=False)
However, when I run the server, I get the following error:
Unhandled exception in thread started by <function
check_errors.<locals>.wrapper at 0x111c619d8>
Traceback (most recent call last):
File "/Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/site-packages/django/utils/autoreload.py",
line 227, in wrapper
fn(*args, **kwargs)
File "/Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/site-packages/django/core/management/commands/runserver.py",
line 117, in inner_run
autoreload.raise_last_exception()
File "/Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/site-packages/django/utils/autoreload.py",
line 250, in raise_last_exception
six.reraise(*_exception)
File "/Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/site-packages/django/utils/six.py",
line 685, in reraise
raise value.with_traceback(tb)
File "/Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/site-packages/django/utils/autoreload.py",
line 227, in wrapper
fn(*args, **kwargs)
File "/Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/site-packages/django/__init__.py",
line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/site-packages/django/apps/registry.py",
line 108, in populate
app_config.import_models()
File "/Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/site-packages/django/apps/config.py",
line 202, in import_models
self.models_module = import_module(models_module_name)
File "/Applications/Anaconda/anaconda/envs/DjangoEnv/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 "/Users/gr/Desktop/PycharmProjects/DjangoWebsite/users/models.py",
line 2, in <module>
from django.contrib.gis.db import models as gis_models
File "/Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/site-packages/django/contrib/gis/db/models/__init__.py",
line 3, in <module>
from django.contrib.gis.db.models.aggregates import * # NOQA
File "/Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/site-packages/django/contrib/gis/db/models/aggregates.py",
line 1, in <module>
from django.contrib.gis.db.models.fields import ExtentField
File "/Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/site-packages/django/contrib/gis/db/models/fields.py",
line 3, in <module>
from django.contrib.gis import forms, gdal
File "/Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/site-packages/django/contrib/gis/forms/__init__.py",
line 3, in <module>
from .fields import ( # NOQA
File "/Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/site-packages/django/contrib/gis/forms/fields.py",
line 4, in <module>
from django.contrib.gis.geos import GEOSException, GEOSGeometry
File "/Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/site-packages/django/contrib/gis/geos/__init__.py",
line 18, in <module>
HAS_GEOS = geos_version_info()['version'] >= '3.3.0'
File "/Applications/Anaconda/anaconda/envs/DjangoEnv/lib/python3.6/site-packages/django/contrib/gis/geos/libgeos.py",
line 196, in geos_version_info
raise GEOSException('Could not parse version info string "%s"' % ver)
django.contrib.gis.geos.error.GEOSException: Could not parse version info string "3.6.2-CAPI-1.10.2 4d2925d6"
This is a known issue, which has been fixed and will be rolled out in Django v1.11.5.
If you can't wait for 1.11.5 or don't want to run on the dev branch, you can go to a previous version of geos:
brew switch geos 3.6.1