please help to solve the problem.
I'm trying to use wysiwyg-Editor:
https://github.com/divio/djangocms-text-ckeditor
models.py:
from django.db import models
from djangocms_text_ckeditor.fields import HTMLField
class News(models.Model):
text = models.HTMLField(
'Основной текст',
max_length=50000,
blank=False,
)
settings.py:
INSTALLED_APPS = (
'djangocms_text_ckeditor',
)
when trying to use the command:
python manage.py schemamigration app_news --auto
I get the following error message:
File "/home/kalinins/.virtualenvs/blogik5/local/lib/python2.7/site-packages/django/conf/__init__.py", line 49, in _setup
self._wrapped = Settings(settings_module)
File "/home/kalinins/.virtualenvs/blogik5/local/lib/python2.7/site-packages/django/conf/__init__.py", line 128, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/home/kalinins/.virtualenvs/blogik5/local/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
File "/home/kalinins/.virtualenvs/blogik5/blogik5/settings.py", line 149, in <module>
mod = import_module(app)
NameError: name 'import_module' is not defined
The error doesn't seem to have anything to do with wsyiwyg-editor: you are calling import_module(app) in your settings.py file, but have not defined or imported that function in that file.
Related
I tried to use django_enums and got an error with list(cls) when making migrations:
(venv:SFS)rita#rita-notebook:~/Serpentarium/ServiceForServices/project/serviceforservices$ python manage.py makemigrations
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/home/rita/Serpentarium/ServiceForServices/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/home/rita/Serpentarium/ServiceForServices/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 341, in execute
django.setup()
File "/home/rita/Serpentarium/ServiceForServices/venv/local/lib/python2.7/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/rita/Serpentarium/ServiceForServices/venv/local/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/home/rita/Serpentarium/ServiceForServices/venv/local/lib/python2.7/site-packages/django/apps/config.py", line 199, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/rita/Serpentarium/ServiceForServices/project/serviceforservices/service/models.py", line 84, in <module>
class EmployeesStatus(models.Model):
File "/home/rita/Serpentarium/ServiceForServices/project/serviceforservices/service/models.py", line 86, in EmployeesStatus
status = enum.EnumField(StatusEnum, default=StatusEnum.AT)
File "/home/rita/Serpentarium/ServiceForServices/venv/local/lib/python2.7/site-packages/django_enums/enum.py", line 53, in __init__
kwargs['max_length'] = self.enum.get_max_length()
File "/home/rita/Serpentarium/ServiceForServices/venv/local/lib/python2.7/site-packages/django_enums/enum.py", line 39, in get_max_length
return len(max(list(cls), key=(lambda x: len(x.key))).key)
TypeError: 'type' object is not iterable
I installed django-enums, enum and six:
(venv:SFS)rita#rita-notebook:~/Serpentarium/ServiceForServices/project/serviceforservices$ pip install django-enums
(venv:SFS)rita#rita-notebook:~/Serpentarium/ServiceForServices/project/serviceforservices$ pip install enum
(venv:SFS)rita#rita-notebook:~/Serpentarium/ServiceForServices/project/serviceforservices$ pip install six
Using in Models.py:
...
from django_enums import enum
...
class StatusEnum(enum.Enum):
__order__ = 'AT BT BC AC' # for python 2
AT = (u'АВ', u'Активен временно')
BT = (u'БВ', u'Блокирован временно')
BC = (u'БП', u'Блокирован постоянно')
AC = (u'АП', u'Активен постоянно')
class EmployeesStatus(models.Model):
name = models.CharField(max_length=128)
status = enum.EnumField(StatusEnum, default=StatusEnum.AT)
It seems like project is alive, it also was updated for Django 1.10 and compartible with python 2 allegedly. So, what I'm doing wrong?
It looks like you are trying to use the backported enum from the 3.4 stdlib, but you installed enum -- you need to install enum34.
Trying to use django-shopify-sync in a Django 1.9 project. When loading the config for the app it gives me the following error, likely because it's trying to load some models in the config?
Tried moving the the two imports that eventually import models into the ready() function below, but still getting the same error. Culpirt lines 2 and 3 in the following file https://github.com/andresdouglas/django-shopify-sync/blob/master/shopify_sync/apps.py
The error is:
$ python manage.py runserver
Unhandled exception in thread started by <function wrapper at 0x10753e500>
Traceback (most recent call last):
File "/Users/andres/.virtualenvs/[...]/lib/python2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/Users/andres/.virtualenvs/[...]/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "/Users/andres/.virtualenvs/[...]/lib/python2.7/site-packages/django/utils/autoreload.py", line 249, in raise_last_exception
six.reraise(*_exception)
File "/Users/andres/.virtualenvs/[...]/lib/python2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/Users/andres/.virtualenvs/[...]/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/andres/.virtualenvs/[...]/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/Users/andres/.virtualenvs/[...]/lib/python2.7/site-packages/django/apps/config.py", line 116, in create
mod = import_module(mod_path)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/andres/.virtualenvs/[...]/src/shopify-sync/shopify_sync/apps.py", line 2, in <module>
from shopify_sync.handlers import webhook_received_handler
File "/Users/andres/.virtualenvs/[...]/src/shopify-sync/shopify_sync/handlers.py", line 3, in <module>
from .models import (CustomCollection, Customer, Order, Product, Shop,
File "/Users/andres/.virtualenvs/[...]/src/shopify-sync/shopify_sync/models/__init__.py", line 3, in <module>
from .address import Address
File "/Users/andres/.virtualenvs/[...]/src/shopify-sync/shopify_sync/models/address.py", line 6, in <module>
from .base import ShopifyResourceModel
File "/Users/andres/.virtualenvs/[...]/src/shopify-sync/shopify_sync/models/base.py", line 144, in <module>
class ShopifyResourceModel(models.Model):
File "/Users/andres/.virtualenvs/[...]/lib/python2.7/site-packages/django/db/models/base.py", line 94, in __new__
app_config = apps.get_containing_app_config(module)
File "/Users/andres/.virtualenvs/[...]/lib/python2.7/site-packages/django/apps/registry.py", line 239, in get_containing_app_config
self.check_apps_ready()
File "/Users/andres/.virtualenvs/[...]/lib/python2.7/site-packages/django/apps/registry.py", line 124, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
UPDATE: If I move the following lines (model imports) https://github.com/andresdouglas/django-shopify-sync/blob/master/shopify_sync/handlers.py#L3-L4 to inside get_topic_models it seems to fix the error. But that's kind of dirty, can anyone come up with a better solution?
If you move the following lines (model imports) https://github.com/andresdouglas/django-shopify-sync/blob/master/shopify_sync/handlers.py#L3-L4
from .models import (CustomCollection, Customer, Order, Product, Shop,
SmartCollection)
inside get_topic_models it seems to fix the error. But that's kind of dirty, can anyone come up with a better solution?
It looks like you may have an ordering issue. Make sure your application is in the INSTALLED_APPS tuple after django-shopify-sync. You can find a few more details in the Application registry documentation.
As unsatisfying as an inline import is, you may be stuck with it. I'd suggest moving
from shopify_sync.handlers import webhook_received_handler
from shopify_webhook.signals import webhook_received
into the ready method in apps.py. This will delay the import until the models are ready.
The change I tried is:
diff --git a/shopify_sync/apps.py b/shopify_sync/apps.py
index 663b43b..0bc1fcc 100644
--- a/shopify_sync/apps.py
+++ b/shopify_sync/apps.py
## -1,7 +1,5 ##
from django.apps import AppConfig
-from shopify_sync.handlers import webhook_received_handler
-from shopify_webhook.signals import webhook_received
-
+import importlib
class ShopifySyncConfig(AppConfig):
"""
## -16,5 +14,9 ## class ShopifySyncConfig(AppConfig):
The ready() method is called after Django setup.
"""
+ signals_webhook_received = importlib.import_module('.signals', package='shopify_webhook')
+ handlers_webhook_received_handler = importlib.import_module('.handlers', package='shopify_sync')
+
# Connect shopify_webhook's webhook_received signal to our synchronisation handler.
- webhook_received.connect(webhook_received_handler, dispatch_uid = 'shopify_sync_webhook_received_handler')
+ signals_webhook_received.webhook_received.connect(handlers_webhook_received_handler.webhook_received_handler, dispatch_uid = 'shopify_sync_webhook_received_handler')
+
I am new to django. Want to create tables in the Database of my project, so I searched the tutorial.
models.py:
from django.db import models
class Blah(models.Model):
first = models.IntegerField()
second = models.IntegerField()
Script to write data into db:
from django.conf import settings
settings.configure()
from core.models import Blah
b = Blah(first = 1, second = 2)
b.save()
When I am trying to launch the script with django 1.9, it gives me the error:
C:\Python27\Scripts\reports>to_db.py
Traceback (most recent call last):
File "C:\Python27\Scripts\reports\to_db.py", line 4, in <module>
from core.models import Blah
File "C:\Python27\Scripts\reports\core\models.py", line 5, in <module>
class Blah(models.Model):
File "C:\Python27\lib\site-packages\django\db\models\base.py", line 94, in __new__
app_config = apps.get_containing_app_config(module)
File "C:\Python27\lib\site-packages\django\apps\registry.py", line 239, in get_containing_app_config
self.check_apps_ready()
File "C:\Python27\lib\site-packages\django\apps\registry.py", line 124, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
I have already added the app to INSTALLED_APPS and I am able to do the exact same commands with "manage.py shell", but not with the script.
What am I missing here?
Thanks
If you do need to script against Django (and the ORM), you'll want to use the shell admin command, passing your script as input to it. Related question
I have a model in one of my apps which is throwing an error when I run "python.py makemigrations signup." I have spent the last two days pouring through documentation (and Google) trying to figure out why this error is happening. Unfortunately I have come up with nothing.
What I am trying to do is include an app in my project. The app sits in the root directory of my python directory (not in a subfolder of of my project). Here is my code:
from django.db import models
class CompanyInfo(models.Model):
companyID = model.AutoField(primary_key=True)
companyName = model.CharField(max_length=100)
companyURL = model.URLField(max_length=100)
companyEmail = model.EmailField(max_length=254)
companyFEIN = model.CharField(max_length=50)
companyUsername= model.CharField(max_length=100)
companyPassword = model.CharField(max_length=100)
class CompanyContact(models.Model):
ccID = model.AutoField(primary_key=True)
ccFirstName = model.CharField(max_length=100)
ccLastName = model.CharField(max_length=100)
ccEmail = model.EmailField(max_length=254)
ccPhone = model.IntegerField(max_length=20)
The exact error that is printed to the console reads:
root#ubuntu1204:/home/humanoid# python manage.py makemigrations humanoid
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 312, in execute
django.setup()
File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/usr/local/lib/python2.7/dist-packages/django/apps/config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/humanoid/signup/models.py", line 3, in <module>
class CompanyInfo(models.Model):
File "/home/humanoid/signup/models.py", line 4, in CompanyInfo
companyID = model.AutoField(primary_key=True)
NameError: name 'model' is not defined
It looks like you have dropped the 's' on models. You need to change your use of model to models.
For example:
companyID = model.AutoField(primary_key=True)
Needs to be:
companyID = models.AutoField(primary_key=True)
It looks like from the import it should be models (plural) and not model.
Whenever I type this command in Python GUI:
from django.db import models
it gives me an error like this
Traceback (most recent call last):
File "<pyshell#12>", line 1, in <module>
from django.db import models
File "C:\Python27\lib\site-packages\django\db\models\__init__.py", line 5, in <module>
from django.db.models.query import Q
File "C:\Python27\lib\site-packages\django\db\models\query.py", line 17, in <module>
from django.db.models.deletion import Collector
File "C:\Python27\lib\site-packages\django\db\models\deletion.py", line 4, in <module>
from django.db.models import signals, sql
File "C:\Python27\lib\site-packages\django\db\models\sql\__init__.py", line 4, in <module>
from django.db.models.sql.subqueries import *
File "C:\Python27\lib\site-packages\django\db\models\sql\subqueries.py", line 12, in <module>
from django.db.models.sql.query import Query
File "C:\Python27\lib\site-packages\django\db\models\sql\query.py", line 22, in <module>
from django.db.models.sql import aggregates as base_aggregates_module
File "C:\Python27\lib\site-packages\django\db\models\sql\aggregates.py", line 9, in <module>
ordinal_aggregate_field = IntegerField()
File "C:\Python27\lib\site-packages\django\db\models\fields\__init__.py", line 116, in __init__
self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_TABLESPACE
File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 54, in __getattr__
self._setup(name)
File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 47, in _setup
% (desc, ENVIRONMENT_VARIABLE))
ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
What can it be the problem? I have django in directory C:\Python27\Lib\site-packages\django\db and in there i have a file called models.
This is the pic
Bizarre isn't it?
Not all of Django supports simply being loaded as a Python module, unfortunately; you need to use the means provided by Django itself to bootstrap the environment needed to load stuff like models.
One option is to use the Django shell but it's also possible to use a purely programmatic solution from your own code. See https://docs.djangoproject.com/en/dev/topics/settings/ for all the options.
Here's also an example by somebody else https://gist.github.com/jordanorelli/1025419 but I haven't verified if it's up to date.
The answer is in the error message:
You must either define the environment variable DJANGO_SETTINGS_MODULE or...
For this reason Django provides a shortcut to loading a python shell with Django settings configured:
https://docs.djangoproject.com/en/dev/ref/django-admin/#shell