you may also need to change polls/apps.py to have a config class
On Thu, Dec 3, 2020 at 5:31 PM Ryan Gedwill <ryangedwill@gmail.com> wrote:
you at least need to add 'polls' to your INSTALLED_APPS in settings.py. You should also remove the line you put in manage.py - that file should rarely be touched at all.This is not a system path problemOn Thu, Dec 3, 2020 at 12:38 PM Ennio Santos <ennio.gomide@gmail.com> wrote:I developed some small web app using Django, but I had not used virtual env up to the moment.I am facing the erro above, I can imagine that is related to some kind of path definition that is not properly defined, but have no idea where to begin.My Envwindows 10 homeCurrently using CONDA, version 4.9.2, installed on my "C" driver.# conda environments:#base C:\ProgramData\Anaconda3pranos39 C:\ProgramData\Anaconda3\envs\pranos39agen37 C:\Users\ennio\.conda\envs\agen37agen39 C:\Users\ennio\.conda\envs\agen39baseold C:\Users\ennio\.conda\envs\baseoldpython38 C:\Users\ennio\.conda\envs\python38* d:\conda_env\py38 (this is the one I activate)And the editor is vscode 1.51.1 version. using pylint, and it is pointing to the python env above.I have the driver "D" where is the conda env being used. And also, where is the source code.D:\Linguagem\mooc\code\polls38Tutorial being usedsince it is the first time using the virtual env to build a django app, I decide to use the tutorial available to test:Using the exemplo, as it is.(d:\conda_env\py38) D:\Linguagem\mooc\code\polls38>conda list# packages in environment at d:\conda_env\py38:## Name Version Build Channelasgiref 3.3.1 pyhd3eb1b0_0astroid 2.4.2 py38_0ca-certificates 2020.10.14 0certifi 2020.11.8 py38haa95532_0colorama 0.4.4 py_0django 3.1.3 pyhd3eb1b0_0isort 5.6.4 py_0krb5 1.17.1 hc04afaa_0lazy-object-proxy 1.4.3 py38he774522_0libpq 12.2 h3235a2c_0mccabe 0.6.1 py38_1openssl 1.1.1h he774522_0pip 20.3 py38haa95532_0psycopg2 2.8.5 py38h7a1dbc1_0pylint 2.6.0 py38_0python 3.8.5 h5fd99cc_1pytz 2020.4 pyhd3eb1b0_0setuptools 50.3.1 py38haa95532_1six 1.15.0 py38haa95532_0sqlite 3.33.0 h2a8f88b_0sqlparse 0.4.1 py_0tk 8.6.10 he774522_0toml 0.10.1 py_0vc 14.1 h0510ff6_4vs2015_runtime 14.16.27012 hf0eaf9b_3wheel 0.35.1 pyhd3eb1b0_0wincertstore 0.2 py38_0wrapt 1.11.2 py38he774522_0zlib 1.2.11 h62dcd97_4The settings.py filefrom pathlib import Path# Build paths inside the project like this: BASE_DIR / 'subdir'.BASE_DIR = Path(__file__).resolve().parent.parentprint(BASE_DIR)# Quick-start development settings - unsuitable for production# SECURITY WARNING: keep the secret key used in production secret!SECRET_KEY = '********'# SECURITY WARNING: don't run with debug turned on in production!DEBUG = TrueALLOWED_HOSTS = []# Application definitionINSTALLED_APPS = ['polls.apps.PollsConfig','django.contrib.admin','django.contrib.auth','django.contrib.contenttypes','django.contrib.sessions','django.contrib.messages','django.contrib.staticfiles',]MIDDLEWARE = ['django.middleware.security.SecurityMiddleware','django.contrib.sessions.middleware.SessionMiddleware','django.middleware.common.CommonMiddleware','django.middleware.csrf.CsrfViewMiddleware','django.contrib.auth.middleware.AuthenticationMiddleware','django.contrib.messages.middleware.MessageMiddleware','django.middleware.clickjacking.XFrameOptionsMiddleware',]ROOT_URLCONF = 'polls38.urls'TEMPLATES = [{'BACKEND': 'django.template.backends.django.DjangoTemplates','DIRS': [],'APP_DIRS': True,'OPTIONS': {'context_processors': ['django.template.context_processors.debug','django.template.context_processors.request','django.contrib.auth.context_processors.auth','django.contrib.messages.context_processors.messages',],},},]WSGI_APPLICATION = 'polls38.wsgi.application'# DatabaseDATABASES = {'default': {'ENGINE': 'django.db.backends.sqlite3','NAME': BASE_DIR / 'db.sqlite3',}}# Password validationAUTH_PASSWORD_VALIDATORS = [{'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',},{'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',},{'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',},{'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',},]# InternationalizationLANGUAGE_CODE = 'pt-br'TIME_ZONE = 'America/Sao_Paulo'USE_I18N = TrueUSE_L10N = TrueUSE_TZ = True# Static files (CSS, JavaScript, Images)STATIC_URL = '/static/'To create de app "polls" I had to use the command:django-admin startapp polls polls38/polls (firstly I created the folder).I was facing an error, when running "python manage.py runserver".ERROR: module no found "polls".I solved the problem, by adding at the manage.py the path to the app, as bellow (i do not believe that its the best solution)def main():"""Run administrative tasks."""sys.path.append('D:/linguagem/mooc/code/polls38/polls38')os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'polls38.settings')try:from django.core.management import execute_from_command_lineexcept 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 excexecute_from_command_line(sys.argv)I was able to run the first and second part of the tutorial.In the third part, after improving the polls/views, another problem showed-up.And if I try to run, the follwing error occurs:when I issue the command "python manage.py runserver"(d:\conda_env\py38) D:\Linguagem\mooc\code\polls38>python manage.py runserverD:\Linguagem\mooc\code\polls38D:\Linguagem\mooc\code\polls38Watching for file changes with StatReloaderPerforming system checks...Exception in thread django-main-thread:Traceback (most recent call last):File "d:\conda_env\py38\lib\threading.py", line 932, in _bootstrap_innerself.run()File "d:\conda_env\py38\lib\threading.py", line 870, in runself._target(*self._args, **self._kwargs)File "d:\conda_env\py38\lib\site-packages\django\utils\autoreload.py", line 53, in wrapperfn(*args, **kwargs)File "d:\conda_env\py38\lib\site-packages\django\core\management\commands\runserver.py", line 118, in inner_runself.check(display_num_errors=True)File "d:\conda_env\py38\lib\site-packages\django\core\management\base.py", line 392, in checkall_issues = checks.run_checks(File "d:\conda_env\py38\lib\site-packages\django\core\checks\registry.py", line 70, in run_checksnew_errors = check(app_configs=app_configs, databases=databases)File "d:\conda_env\py38\lib\site-packages\django\core\checks\urls.py", line 13, in check_url_configreturn check_resolver(resolver)File "d:\conda_env\py38\lib\site-packages\django\core\checks\urls.py", line 23, in check_resolverreturn check_method()File "d:\conda_env\py38\lib\site-packages\django\urls\resolvers.py", line 408, in checkfor pattern in self.url_patterns:File "d:\conda_env\py38\lib\site-packages\django\utils\functional.py", line 48, in __get__res = instance.__dict__[self.name] = self.func(instance)File "d:\conda_env\py38\lib\site-packages\django\urls\resolvers.py", line 589, in url_patternspatterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)File "d:\conda_env\py38\lib\site-packages\django\utils\functional.py", line 48, in __get__res = instance.__dict__[self.name] = self.func(instance)File "d:\conda_env\py38\lib\site-packages\django\urls\resolvers.py", line 582, in urlconf_modulereturn import_module(self.urlconf_name)File "d:\conda_env\py38\lib\importlib\__init__.py", line 127, in import_modulereturn _bootstrap._gcd_import(name[level:], package, level)File "<frozen importlib._bootstrap>", line 1014, in _gcd_importFile "<frozen importlib._bootstrap>", line 991, in _find_and_loadFile "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlockedFile "<frozen importlib._bootstrap>", line 671, in _load_unlockedFile "<frozen importlib._bootstrap_external>", line 783, in exec_moduleFile "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removedFile "D:\Linguagem\mooc\code\polls38\polls38\urls.py", line 20, in <module>path('', include('polls38.polls.urls')),File "d:\conda_env\py38\lib\site-packages\django\urls\conf.py", line 34, in includeurlconf_module = import_module(urlconf_module)File "d:\conda_env\py38\lib\importlib\__init__.py", line 127, in import_modulereturn _bootstrap._gcd_import(name[level:], package, level)File "<frozen importlib._bootstrap>", line 1014, in _gcd_importFile "<frozen importlib._bootstrap>", line 991, in _find_and_loadFile "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlockedFile "<frozen importlib._bootstrap>", line 671, in _load_unlockedFile "<frozen importlib._bootstrap_external>", line 783, in exec_moduleFile "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removedFile "D:\Linguagem\mooc\code\polls38\polls38\polls\urls.py", line 3, in <module>from . import viewsFile "D:\Linguagem\mooc\code\polls38\polls38\polls\views.py", line 7, in <module>from .models import QuestionFile "D:\Linguagem\mooc\code\polls38\polls38\polls\models.py", line 6, in <module>class Question(models.Model):File "d:\conda_env\py38\lib\site-packages\django\db\models\base.py", line 113, in __new__raise RuntimeError(RuntimeError: Model class polls38.polls.models.Question doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.Any help on how to fix?tks a lot!!--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/54c2664d-315b-46c4-baae-c7eddab7c19cn%40googlegroups.com.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CALG8KeD8eb%2B9OSPze1u5VP%3DSsx39b%2BQaP-HL4-QcMxYV5eXRSA%40mail.gmail.com.
No comments:
Post a Comment