ModuleNotFoundError: нет модуля с именем "captcha"
Я пытаюсь добавить Google Captcha в форму Django, но по-прежнему получаю следующую ошибку, даже когда все было успешно настроено.
File
"C:\Users\PC\AppData\Local\Programs\Python\Python313\Lib\threading.py",
line 1041, in _bootstrap_inner
self.run()
~~~~~~~~^^ File "C:\Users\PC\AppData\Local\Programs\Python\Python313\Lib\threading.py",
line 992, in run
self._target(*self._args, **self._kwargs)
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\PC\OneDrive\Desktop\geekswebdevlopmentprojects\recaptcha\.venv\Lib\site-packages\django\utils\autoreload.py",
line 64, in wrapper
fn(*args, **kwargs)
~~^^^^^^^^^^^^^^^^^ File "C:\Users\PC\OneDrive\Desktop\geekswebdevlopmentprojects\recaptcha\.venv\Lib\site-packages\django\core\management\commands\runserver.py",
line 124, in inner_run
autoreload.raise_last_exception()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^ File "C:\Users\PC\OneDrive\Desktop\geekswebdevlopmentprojects\recaptcha\.venv\Lib\site-packages\django\utils\autoreload.py",
line 86, in raise_last_exception
raise _exception[1] File "C:\Users\PC\OneDrive\Desktop\geekswebdevlopmentprojects\recaptcha\.venv\Lib\site-packages\django\core\management\__init__.py",
line 394, in execute
autoreload.check_errors(django.setup)()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^ File "C:\Users\PC\OneDrive\Desktop\geekswebdevlopmentprojects\recaptcha\.venv\Lib\site-packages\django\utils\autoreload.py",
line 64, in wrapper
fn(*args, **kwargs)
~~^^^^^^^^^^^^^^^^^ File "C:\Users\PC\OneDrive\Desktop\geekswebdevlopmentprojects\recaptcha\.venv\Lib\site-packages\django\__init__.py",
line 24, in setup
apps.populate(settings.INSTALLED_APPS)
~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\PC\OneDrive\Desktop\geekswebdevlopmentprojects\recaptcha\.venv\Lib\site-packages\django\apps\registry.py",
line 91, in populate
app_config = AppConfig.create(entry) File "C:\Users\PC\OneDrive\Desktop\geekswebdevlopmentprojects\recaptcha\.venv\Lib\site-packages\django\apps\config.py",
line 193, in create
import_module(entry)
~~~~~~~~~~~~~^^^^^^^ File "C:\Users\PC\AppData\Local\Programs\Python\Python313\Lib\importlib\__init__.py",
line 88, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "<frozen importlib._bootstrap>", line 1387, in _gcd_import File
"<frozen importlib._bootstrap>", line 1360, in _find_and_load File
"<frozen importlib._bootstrap>", line 1324, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'captcha'
** Есть ли лучший способ заставить это работать?**
Вот конфигурация моего кода, и я установил pip install django-recaptcha.
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'contact',
'captcha',
]
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
from django import forms
from django_recaptcha.fields import ReCaptchaField
from django_recaptcha.widgets import ReCaptchaV2Checkbox
class ContactForm(forms.Form):
email = forms.EmailField()
feedback = forms.CharField(widget=forms.Textarea)
captcha = ReCaptchaField(widget=ReCaptchaV2Checkbox)
Имя модуля - django_recaptcha
, таким образом:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'contact',
# 'captcha',
'django_recaptcha',
]
Even when I got the public key and the secret key on the setting.py file, I still keep getting the issue below. I have tried to fix it, but it does not work still.
Now I got it like this, but I still keep getting the issue below.
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'contact',
'django_recaptcha',
]
RECAPTCHA_PUBLIC_KEY = os.getenv("RECAPTCHA_PUBLIC_KEY")
RECAPTCHA_SECRET_KEY = os.getenv("RECAPTCHA_SECRET_KEY")
ERRORS:
?: (django_recaptcha.recaptcha_test_key_error) RECAPTCHA_PRIVATE_KEY or RECAPTCHA_PUBLIC_KEY is making use of the Google test keys and will not behave as expected in a production environment
HINT: Update settings.RECAPTCHA_PRIVATE_KEY and/or settings.RECAPTCHA_PUBLIC_KEY. Alternatively this check can be ignored by adding `SILENCED_SYSTEM_CHECKS = ['django_recaptcha.recaptcha_test_key_error']` to your settings file.