I have imported the following header file
from django.contrib.postgres.fields import ArrayField
Used the following in the model
question_array = ArrayField(models.IntegerField, blank=True,)
i get the following error
Traceback (most recent call last)
File "C:\Program Files (x86)\Python\Python35-32\lib\site-packages\django-1.10.4-py3.5.egg\django\__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Program Files (x86)\Python\Python35-32\lib\site-packages\django-1.10.4-py3.5.egg\django\apps\registry.py", line 108, in populate
app_config.import_models(all_models)
File "C:\Program Files (x86)\Python\Python35-32\lib\site-packages\django-1.10.4-py3.5.egg\django\apps\config.py", line 199, in import_models
self.models_module = import_module(models_module_name)
File "C:\Program Files (x86)\Python\Python35-32\lib\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 "C:\Users\DELL\Desktop\cstrom\comp\models.py", line 24, in <module>
class User(models.Model):
File "C:\Program Files (x86)\Python\Python35-32\lib\site-packages\django-1.10.4-py3.5.egg\django\db\models\base.py", line 157, in __new__
new_class.add_to_class(obj_name, obj)
File "C:\Program Files (x86)\Python\Python35-32\lib\site-packages\django-1.10.4-py3.5.egg\django\db\models\base.py", line 316, in add_to_class
value.contribute_to_class(cls, name)
File "C:\Program Files (x86)\Python\Python35-32\lib\site-packages\django-1.10.4-py3.5.egg\django\db\models\fields\__init__.py", line 689, in contribute_to_class
self.set_attributes_from_name(name)
File "C:\Program Files (x86)\Python\Python35-32\lib\site-packages\django-1.10.4-py3.5.egg\django\contrib\postgres\fields\array.py", line 75, in set_attributes_from_name
self.base_field.set_attributes_from_name(name)
TypeError: set_attributes_from_name() missing 1 required positional argument: 'name'
As per the docs
You still need to fully define the field inside the array field
question_array = ArrayField(models.IntegerField(null=True, blank=True), blank=True,)
models.IntegerField is a function not a property, so you will be required to call it like a function. () at the end
question_array = ArrayField(models.IntegerField(blank=True), blank=True,)
Read more about it here.
Related
I am trying to run a project About sdn mininet&ryu controller. source: https://github.com/archanas23/SDN-Project but when I try to run a dumper file step 3, I get this error.
Command:
PYTHONPATH=. ./bin/ryu-manager --verbose --observe-links ryu/topology/dumper.py ./ryu/controller/controller.py
Error:
loading app ./ryu/controller/controller.py
Traceback (most recent call last):
File "./bin/ryu-manager", line 19, in <module>
main()
File "/home/saber/ryu/ryu/cmd/manager.py", line 98, in main
app_mgr.load_apps(app_lists)
File "/home/saber/ryu/ryu/base/app_manager.py", line 415, in load_apps
cls = self.load_app(app_cls_name)
File "/home/saber/ryu/ryu/base/app_manager.py", line 392, in load_app
mod = utils.import_module(name)
File "/home/saber/ryu/ryu/utils.py", line 99, in import_module
return _import_module_file(modname)
File "/home/saber/ryu/ryu/utils.py", line 88, in _import_module_file
return load_source(modname, abspath)
File "/home/saber/ryu/ryu/utils.py", line 42, in load_source
return loader.load_module(name)
File "<frozen importlib._bootstrap_external>", line 522, in _check_name_wrapper
File "<frozen importlib._bootstrap_external>", line 1027, in load_module
File "<frozen importlib._bootstrap_external>", line 852, in load_module
File "<frozen importlib._bootstrap>", line 265, in _load_module_shim
File "<frozen importlib._bootstrap>", line 702, in _load
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 848, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/saber/ryu/ryu/controller/controller.py", line 58, in <module>
CONF.register_cli_opts([
File "/home/saber/.local/lib/python3.8/site-packages/oslo_config/cfg.py", line 2077, in __inner
result = f(self, *args, **kwargs)
File "/home/saber/.local/lib/python3.8/site-packages/oslo_config/cfg.py", line 2363, in register_cli_opts
self.register_cli_opt(opt, group, clear_cache=False)
File "/home/saber/.local/lib/python3.8/site-packages/oslo_config/cfg.py", line 2081, in __inner
return f(self, *args, **kwargs)
File "/home/saber/.local/lib/python3.8/site-packages/oslo_config/cfg.py", line 2355, in register_cli_opt
raise ArgsAlreadyParsedError("cannot register CLI option")
oslo_config.cfg.ArgsAlreadyParsedError: arguments already parsed: cannot register CLI option
I'm trying to run a django code an imx6 yocto build that i made. The basic example went fine and smooth. So i decided to run my own django production from a project im working and i get the following:
root#imx6ulevk:/home/mdwb-main# python manage.py runserver 147.106.17.9:8000
Watching for file changes with StatReloader
Exception in thread django-main-thread:
Traceback (most recent call last):
File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
self.run()
File "/usr/lib/python3.5/threading.py", line 862, in run
self._target(*self._args, **self._kwargs)
File "/usr/lib/python3.5/site-packages/django/utils/autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "/usr/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "/usr/lib/python3.5/site-packages/django/utils/autoreload.py", line 77, in raise_last_exception
raise _exception[1]
File "/usr/lib/python3.5/site-packages/django/core/management/__init__.py", line 337, in execute
autoreload.check_errors(django.setup)()
File "/usr/lib/python3.5/site-packages/django/utils/autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "/usr/lib/python3.5/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/lib/python3.5/site-packages/django/apps/registry.py", line 114, in populate
app_config.import_models()
File "/usr/lib/python3.5/site-packages/django/apps/config.py", line 211, 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 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 693, in exec_module
File "<frozen importlib._bootstrap_external>", line 799, in get_code
File "<frozen importlib._bootstrap_external>", line 759, in source_to_code
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "/home/mdwb-main/api_cloud/models.py", line 15
return f'{self.cloud_interval} foi cadastrado com sucesso!'
^
SyntaxError: invalid syntax
The code in models.py is the following:
from django.db import models
# Create your models here.
class Initial_config(models.Model):
#complement = models.CharField(max_length=30,null=True)
cloud_interval = models.IntegerField()
device_interval = models.IntegerField()
class Meta:
verbose_name = 'config'
verbose_name_plural = 'configs'
def __str__(self):
return f'{self.cloud_interval} foi cadastrado com sucesso!'
I tried to change the ' to " remove the {self.cloud_interval}, but none of them was sucessful.
Why this happens? How to fix it?
f-strings can only be used from Python 3.6 onwards.
If you want to remain with Python 3.5, you can change your code to:
def __str__(self):
return '%s foi cadastrado com sucesso!' % self.cloud_interval
That said, Python 3.5 is no longer officially supported; upgrading to 3.6 or above is highly recommended. See https://endoflife.date/python for more.
I've installed Django 3.1.4 and djangorestframework 3.12.2.
I am attempting to run makemigrations for a music website I am building and I keep getting this error in the terminal and haven't been able to figure out what is causing it.
(Django_React) PS C:\Users\BB_SO\desktop\dev\Django_React\music_site> python .\manage.py makemigrations Traceback (most recent call last):
File ".\manage.py", line 22, in <module>
main()
File ".\manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "C:\Users\BB_SO\desktop\dev\Django_React\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "C:\Users\BB_SO\desktop\dev\Django_React\lib\site-packages\django\core\management\__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\BB_SO\desktop\dev\Django_React\lib\site-packages\django\core\management\base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\BB_SO\desktop\dev\Django_React\lib\site-packages\django\core\management\base.py", line 368, in execute
self.check()
File "C:\Users\BB_SO\desktop\dev\Django_React\lib\site-packages\django\core\management\base.py", line 396, in check
databases=databases,
File "C:\Users\BB_SO\desktop\dev\Django_React\lib\site-packages\django\core\checks\registry.py", line 70, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "C:\Users\BB_SO\desktop\dev\Django_React\lib\site-packages\django\core\checks\urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "C:\Users\BB_SO\desktop\dev\Django_React\lib\site-packages\django\core\checks\urls.py", line 23, in check_resolver
return check_method()
File "C:\Users\BB_SO\desktop\dev\Django_React\lib\site-packages\django\urls\resolvers.py", line 408, in check
for pattern in self.url_patterns:
File "C:\Users\BB_SO\desktop\dev\Django_React\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\BB_SO\desktop\dev\Django_React\lib\site-packages\django\urls\resolvers.py", line 589, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\Users\BB_SO\desktop\dev\Django_React\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\BB_SO\desktop\dev\Django_React\lib\site-packages\django\urls\resolvers.py", line 582, in urlconf_module
return import_module(self.urlconf_name)
File "C:\Users\BB_SO\anaconda3\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\BB_SO\desktop\dev\Django_React\music_site\music_site\urls.py", line 19, in <module>
urlpatterns = [path("admin/", admin.site.urls), path("", include("api.urls"))]
File "C:\Users\BB_SO\desktop\dev\Django_React\lib\site-packages\django\urls\conf.py", line 34, in include
urlconf_module = import_module(urlconf_module)
File "C:\Users\BB_SO\anaconda3\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\BB_SO\desktop\dev\Django_React\music_site\api\urls.py", line 2, in <module>
from .views import RoomView
File "C:\Users\BB_SO\desktop\dev\Django_React\music_site\api\views.py", line 3, in <module>
from .serlializer import RoomSerializer
ModuleNotFoundError: No module named 'api.serlializer'
Here my serializer.py file content:
from rest_framework import serializer
from .models import Room
class RoomSeralizer(seriarlizers.ModelSerializer):
class Meta:
model = Room
fields = (
"id",
"code",
"host",
"guest_can_pause",
"vote_to_skip",
"created_at",
)
Does anyone know what might be causing this error? I am still very new to coding and am using vscode if that helps at all. Thanks in advance for your help!
In serializer.py Try:
from rest_framework import serializers
Django-rest framework doesn't have any API called serializer.
More: https://www.django-rest-framework.org/api-guide/serializers/
import should be
from rest_framework import serializers
I am trying build a machine learning API using DJANGO rest framework API. After creating a project and configuring model.py of created project 'MyAPI' ,for required approvals. And used the following commend to run the server, got following error.
how to fix them ?, Please guide me.
````C:\Users\Padmini\DjangoAPI>python manage.py runserver```
error
Exception in thread django-main-thread:
Traceback (most recent call last):
File "C:\Users\Padmini\AppData\Local\Programs\Python\Python37-32\lib\threading.py", line 926, in _bootstrap_inner
self.run()
File "C:\Users\Padmini\AppData\Local\Programs\Python\Python37-32\lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\Padmini\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "C:\Users\Padmini\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\commands\runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "C:\Users\Padmini\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\utils\autoreload.py", line 76, in raise_last_exception
raise _exception[1]
File "C:\Users\Padmini\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\__init__.py", line 357, in execute
autoreload.check_errors(django.setup)()
File "C:\Users\Padmini\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "C:\Users\Padmini\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\Padmini\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\apps\registry.py", line 114, in populate
app_config.import_models()
File "C:\Users\Padmini\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\apps\config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "C:\Users\Padmini\AppData\Local\Programs\Python\Python37-32\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\Padmini\DjangoAPI\MyAPI\models.py", line 4, in <module>
class approvals(models.Model):
File "C:\Users\Padmini\DjangoAPI\MyAPI\models.py", line 7, in approvals
('Female','Female')
TypeError: 'tuple' object is not callable````
my model.py as following code
from django.db import models
# Create your models here.
class approvals(models.Model):
GENDER_CHOICES= (
('Male', 'Male')
('Female','Female')
)
MARRIED_CHOICES=(
('Yes','Yes'),
('No','No')
)
GRADUATED_CHOICES= (
('Graduate','Graduated'),
('Not_Graduate','Not_Graduate')
)
SELFEMPLOYED_CHOICES=(
('Yes','Yes'),
('No','No')
)
PROPERTY_CHOICES=(
('Rural','Rural'),
('Semiurban','Semiurban'),
('Urban','Urban')
)
firstname=models.CharField(max_length=15)
lastname=models.CharField(max_length=15)
dependants=models.IntegerField(default=0)
applicantincome=models.IntegerField(default=0)
coapplicatincome=models.IntegerField(default=0)
loanamt=models.IntegerField(default=0)
loanterm=models.IntegerField(default=0)
credithistory=models.IntegerField(default=0)
gender=models.CharField(max_length=15, choices=GENDER_CHOICES)
married=models.CharField(max_length=15, choices=MARRIED_CHOICES)
graduatededucation=models.CharField(max_length=15, choices=GRADUATED_CHOICES)
selfemployed=models.CharField(max_length=15, choices=SELFEMPLOYED_CHOICES)
area=models.CharField(max_length=15, choices=PROPERTY_CHOICES)
def __str__(self):
return '{}, {}'.format(self.lastname, self.firstname)`````
Given that I have 4 models:
Project
User (from django.contrib.auth.models)
Sentence
Translation
My django project directories are structured as such:
\myprojname
\project
models.py
\data
models.py
The User model is independent of the Projects and Sentences models but it is linked to the Projects model through the ForeignKey:
myprojname/projects/models.py looks like this:
from django.db import models
from django.contrib.auth.models import User
class Project(models.Model):
project_id = models.AutoField(primary_key=True)
created_on = models.DateTimeField(auto_now_add=True)
updated_on = models.DateTimeField(auto_now=True)
name = models.CharField(max_length=140)
# Admin user for the particular *Project* object.
# Have the rights to write to the *Sentence* model.
owner = models.ForeignKey(User)
# Worker users that only have write access to the *Translation model.
workers = models.ForeignKey(User, blank=True)
myprojname/data/models.py looks like this:
from django.db import models
from django.contrib.auth.models import User
class Sentence(models.Model):
text = models.TextField()
translations = models.ManyToManyField('Translation', blank=True)
class Translation(models.Model):
text = models.TextField()
translator = models.ForeignKey(User)
Now the Project model isn't connected to the Sentence model.
I've tried connecting it with relative imports, i.e. in myprojname/projects/models.py, I did:
from django.db import models
from django.contrib.auth.models import User
from ..data import Sentence
class Project(models.Model):
# ...
sentences = models.ForeignKey(Sentence)
but it returned a ValueError in Python2.7:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "/usr/local/lib/python2.7/dist-packages/django/utils/autoreload.py", line 249, in raise_last_exception
six.reraise(*_exception)
File "/usr/local/lib/python2.7/dist-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
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 202, 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/alvas/data-project/myprojname/project/models.py", line 5, in <module>
from ..data import Sentence
ValueError: Attempted relative import beyond toplevel package
And in Python3, the same error:
Traceback (most recent call last):
File "/home/alvas/.virtualenvs/payer/lib/python3.5/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/home/alvas/.virtualenvs/payer/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "/home/alvas/.virtualenvs/payer/lib/python3.5/site-packages/django/utils/autoreload.py", line 249, in raise_last_exception
six.reraise(*_exception)
File "/home/alvas/.virtualenvs/payer/lib/python3.5/site-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/home/alvas/.virtualenvs/payer/lib/python3.5/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/home/alvas/.virtualenvs/payer/lib/python3.5/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/alvas/.virtualenvs/payer/lib/python3.5/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/home/alvas/.virtualenvs/payer/lib/python3.5/site-packages/django/apps/config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "/home/alvas/.virtualenvs/payer/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 "/home/alvas/data-project/myprojname/project/models.py", line 5, in <module>
from ..data import Sentence
ValueError: attempted relative import beyond top-level package
And when I tried to do a non-relative import in Python3:
from django.db import models
from django.contrib.auth.models import User
from myprojname.data import Sentence
class Project(models.Model):
# ...
sentences = models.ForeignKey(Sentence)
I get:
Traceback (most recent call last):
File "/home/alvas/.virtualenvs/payer/lib/python3.5/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/home/alvas/.virtualenvs/payer/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "/home/alvas/.virtualenvs/payer/lib/python3.5/site-packages/django/utils/autoreload.py", line 249, in raise_last_exception
six.reraise(*_exception)
File "/home/alvas/.virtualenvs/payer/lib/python3.5/site-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/home/alvas/.virtualenvs/payer/lib/python3.5/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/home/alvas/.virtualenvs/payer/lib/python3.5/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/alvas/.virtualenvs/payer/lib/python3.5/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/home/alvas/.virtualenvs/payer/lib/python3.5/site-packages/django/apps/config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "/home/alvas/.virtualenvs/payer/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 "/home/alvas/data-project/myprojname/project/models.py", line 5, in <module>
from myprojname.data import Sentence
ImportError: No module named 'myprojname.data'
How do I connect the models from different apps?
Edited
When I used from data import Sentence in myprojname.project.models.py, it throws an ImportError:
Traceback (most recent call last):
File "/home/alvas/.virtualenvs/statnlp/lib/python3.5/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/home/alvas/.virtualenvs/statnlp/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "/home/alvas/.virtualenvs/statnlp/lib/python3.5/site-packages/django/utils/autoreload.py", line 249, in raise_last_exception
six.reraise(*_exception)
File "/home/alvas/.virtualenvs/statnlp/lib/python3.5/site-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/home/alvas/.virtualenvs/statnlp/lib/python3.5/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/home/alvas/.virtualenvs/statnlp/lib/python3.5/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/alvas/.virtualenvs/statnlp/lib/python3.5/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/home/alvas/.virtualenvs/statnlp/lib/python3.5/site-packages/django/apps/config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "/home/alvas/.virtualenvs/statnlp/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 "/home/alvas/data-project/myprojname/project/models.py", line 5, in <module>
from data import Sentence
ImportError: cannot import name 'Sentence'
Your import should be from data.models import Sentence instead of from myprojname.data import Sentence.