У меня проблема с учебником, за которым я следую. мы дошли до точки тестирования, и я продолжаю получать сообщение об ошибке при запуске
python manage.py test
Вот моя ошибка:
(restapi) chrismaltez@Chriss-MacBook-Pro:~/Desktop/pycharmprojects/UDEMY/restapi/src$ python manage.py test
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
..E
======================================================================
ERROR: src.status.tests (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: src.status.tests
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/unittest/loader.py", line 428, in _find_test_path
module = self._get_module_from_name(name)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/unittest/loader.py", line 369, in _get_module_from_name
__import__(name)
File "/Users/chrismaltez/Desktop/pycharmprojects/UDEMY/restapi/src/status/tests.py", line 6, in <module>
from .models import Status
File "/Users/chrismaltez/Desktop/pycharmprojects/UDEMY/restapi/src/status/models.py", line 20, in <module>
class Status(models.Model): #fb status, instagram post, tween, linkedin post
File "/Users/chrismaltez/Desktop/pycharmprojects/UDEMY/restapi/lib/python3.6/site-packages/django/db/models/base.py", line 118, in __new__
"INSTALLED_APPS." % (module, name)
RuntimeError: Model class src.status.models.Status doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
----------------------------------------------------------------------
Ran 3 tests in 0.096s
Я не понимаю, почему я получаю эту ошибку, потому что у меня есть статус в установленных приложениях здесь:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
#third party
'rest_framework',
#local
'accounts',
'status',
'updates',
]
а затем вот мои модели, в которых говорится, что у меня ошибка:
from django.conf import settings
from django.db import models
def upload_status_image(instance, filename):
return "status/{user}/{filename}".format(user=instance.user, filename=filename)
class StatusQuerySet(models.QuerySet):
pass
class StatusManager(models.Manager):
def get_queryset(self):
return StatusQuerySet(self.model, using=self._db)
# Create your models here.
class Status(models.Model): #fb status, instagram post, tween, linkedin post
user = models.ForeignKey(settings.AUTH_USER_MODEL) # user instance .save
content = models.TextField(null=True, blank=True)
image = models.ImageField(upload_to=upload_status_image, null=True, blank=True) # great 3rd part package = django storanges --> AWS#pip install pillow to handle images
updated = models.DateTimeField(auto_now=True)
timestamp = models.DateTimeField(auto_now_add=True)
objects = StatusManager
def __str__(self):
return str(self.content)[:50]
class Meta:
verbose_name = "Status post"
verbose_name_plural = "Status posts"
@property
def owner(self):
return self.user
я работаю на Mac в django 1.11.8.
Когда я запускаю makemigrations, я не получаю ошибок. когда я запускаю сервер, я не получаю ошибок. я пробовал это решение а> но ничего не получилось.
Любая помощь приветствуется.
-обновление- файловое дерево:
restapi
|-bin
|-include
|-lib
|-scripts
|-src
|-accounts
| |-api
| | |-user
| | | |-__init__.py
| | | |-serializers.py
| | | |-urls.py
| | | |-views.py
| | |-__init__.py
| | |-permissions.py
| | |-serializers.py
| | |-test_user_api.py
| | |-urls.py
| | |-utils.py
| | |-views.py
| |-+migrations
| |-__init__.py
| |-admin.py
| |-apps.py
| |-models.py
| |-tests.py
| |-views.py
|-cfeapi
| |-restconf
| | |-__init__.py
| | |-main.py
| | |-pagination.py
| |-__init__.py
| |-mixins.py
| |-settings.py
| |-urls.py
| |-wsgi.py
|-status
|-api
| |-__init__.py
| |-serializers.py
| |-urls.py
| |-views.py
|+migrations
|-__init__.py
|-admin.py
|-apps.py
|-forms.py
|-models.py
|-tests.py
|-views.py
'status'
(без префиксаsrc
) в вашемINSTALLED_APPS
, поэтому он должен импортировать модель какstatus.models.Status
, но ошибка показываетsrc.status.models.Status
. Если вы покажете расположение файлов в своем проекте, это может указать, в чем проблема. Если в каталогеsrc
есть__init__.py
, попробуйте удалить его. - person Alasdair   schedule 03.08.2018tree
для отображения макета проекта. На Mac вы можете установить его с помощьюbrew
. - person Alasdair   schedule 05.08.2018