Vielen Dank für die schnelle Antwort!
Also einen Fehler hab ich schon gefunden (glaube ich), es war in VS Code ein falscher Interpreter eingestellt. Habe ihn auf folgenden Umgestellt (hoffe das ist korrekt):
Aber erstmal zur PowerShell. Hier die ausgeführten Befehle:
Nun zum Code. Die Django App heißt "toys".
Der Fehler tritt in
Code: Alles auswählen
C:\Users\Robin\HillarDjangoREST\01\restful01\toys\serializers.py
auf:
Code:
Code: Alles auswählen
from rest_framework import serializers
from toys.models import Toy
Output von VS in der Python Debug Console:
Code: Alles auswählen
PS C:\Users\Robin\HillarDjangoREST\01\restful01\toys> & 'c:\Users\Robin\HillarDjangoREST\01\Scripts\python.exe' 'c:\Users\Robin\.vscode\extensions\ms-python.python-2020.7.96456\pythonFiles\lib\python\debugpy\launcher' '61832' '--' 'c:\Users\Robin\HillarDjangoREST\01\restful01\toys\serializers.py'
Traceback (most recent call last):
File "C:\Python38\lib\runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Python38\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "c:\Users\Robin\.vscode\extensions\ms-python.python-2020.7.96456\pythonFiles\lib\python\debugpy\__main__.py", line 45, in <module>
cli.main()
File "c:\Users\Robin\.vscode\extensions\ms-python.python-2020.7.96456\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 430, in main
run()
File "c:\Users\Robin\.vscode\extensions\ms-python.python-2020.7.96456\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 267, in run_file
runpy.run_path(options.target, run_name=compat.force_str("__main__"))
File "C:\Python38\lib\runpy.py", line 265, in run_path
return _run_module_code(code, init_globals, run_name,
File "C:\Python38\lib\runpy.py", line 97, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "C:\Python38\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "c:\Users\Robin\HillarDjangoREST\01\restful01\toys\serializers.py", line 3, in <module>
from rest_framework import serializers
File "C:\Users\Robin\HillarDjangoREST\01\lib\site-packages\rest_framework\serializers.py", line 28, in <module>
from rest_framework.compat import postgres_fields
from django.contrib.postgres import fields as postgres_fields
File "C:\Users\Robin\HillarDjangoREST\01\lib\site-packages\django\contrib\postgres\fields\__init__.py", line 1, in <module>
from .array import * # NOQA
File "C:\Users\Robin\HillarDjangoREST\01\lib\site-packages\django\contrib\postgres\fields\array.py", line 3, in <module>
from django.contrib.postgres import lookups
File "C:\Users\Robin\HillarDjangoREST\01\lib\site-packages\django\contrib\postgres\lookups.py", line 4, in <module>
from .search import SearchVector, SearchVectorExact, SearchVectorField
File "C:\Users\Robin\HillarDjangoREST\01\lib\site-packages\django\contrib\postgres\search.py", line 47, in <module>
class SearchVector(SearchVectorCombinable, Func):
File "C:\Users\Robin\HillarDjangoREST\01\lib\site-packages\django\contrib\postgres\search.py", line 50, in SearchVector
_output_field = SearchVectorField()
File "C:\Users\Robin\HillarDjangoREST\01\lib\site-packages\django\db\models\fields\__init__.py", line 172, in __init__
self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_TABLESPACE
File "C:\Users\Robin\HillarDjangoREST\01\lib\site-packages\django\conf\__init__.py", line 56, in __getattr__
self._setup(name)
File "C:\Users\Robin\HillarDjangoREST\01\lib\site-packages\django\conf\__init__.py", line 35, in _setup
raise ImproperlyConfigured(
django.core.exceptions.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.
PS C:\Users\Robin\HillarDjangoREST\01\restful01\toys> & c:/Users/Robin/HillarDjangoREST/01/Scripts/Activate.ps1
(01) PS C:\Users\Robin\HillarDjangoREST\01\restful01\toys>
Hier der Code von models.py:
Code: Alles auswählen
from django.db import models
class Toy(models.Model):
created = models.DateTimeField(auto_now_add=True)
name = models.CharField(max_length=150, blank=False, default='')
description = models.CharField(max_length=250, blank=True, default='')
toy_category = models.CharField(max_length=200, blank=False, default='')
release_date = models.DateTimeField()
was_included_in_home = models.BooleanField(default=False)
class Meta:
ordering = ('name',)
Und nun zum Abschluss noch der Bereich aus der settings.py des Projekt-Ordners
Code: Alles auswählen
INSTALLED_APPS = [
'rest_framework',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'toys.apps.ToysConfig',
]
Ich kriege nun nicht mehr den ModulNotFound-Error (das liegt mit der anderen Interpreter-Einstellung zusammen, wie anfangs erläutert).
Ich glaube ich habe einen systematischen Fehler bei der Benutzung der virtuellen Umgebung. Leider ist das Buch da nicht wirklich aussagekräftig.
Danke für die Mühe!