Hi All,
I’m pretty much new to Django and Python. Trying to build a Web Application and currently Stuck at below error can someone please guide on resolving this.
python manage.py runserver
Watching for file changes with StatReloader
Performing system checks…Exception in thread django-main-thread:
Traceback (most recent call last):
File “/Users/Kiran.Thota/.pyenv/versions/3.10.2/lib/python3.10/threading.py”, line 1009, in _bootstrap_inner
self.run()
File “/Users/Kiran.Thota/.pyenv/versions/3.10.2/lib/python3.10/threading.py”, line 946, in run
self._target(*self._args, **self._kwargs)
File “/Applications/Training/Project_Amplify/venv/lib/python3.10/site-packages/django/utils/autoreload.py”, line 64, in wrapper
fn(*args, **kwargs)
File “/Applications/Training/Project_Amplify/venv/lib/python3.10/site-packages/django/core/management/commands/runserver.py”, line 134, in inner_run
self.check(display_num_errors=True)
File “/Applications/Training/Project_Amplify/venv/lib/python3.10/site-packages/django/core/management/base.py”, line 486, in check
all_issues = checks.run_checks(
File “/Applications/Training/Project_Amplify/venv/lib/python3.10/site-packages/django/core/checks/registry.py”, line 88, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File “/Applications/Training/Project_Amplify/venv/lib/python3.10/site-packages/django/core/checks/urls.py”, line 16, in check_url_config
return check_resolver(resolver)
File “/Applications/Training/Project_Amplify/venv/lib/python3.10/site-packages/django/core/checks/urls.py”, line 26, in check_resolver
return check_method()
File “/Applications/Training/Project_Amplify/venv/lib/python3.10/site-packages/django/urls/resolvers.py”, line 531, in check
for pattern in self.url_patterns:
File “/Applications/Training/Project_Amplify/venv/lib/python3.10/site-packages/django/utils/functional.py”, line 47, in get
res = instance.dict[self.name] = self.func(instance)
File “/Applications/Training/Project_Amplify/venv/lib/python3.10/site-packages/django/urls/resolvers.py”, line 718, in url_patterns
patterns = getattr(self.urlconf_module, “urlpatterns”, self.urlconf_module)
File “/Applications/Training/Project_Amplify/venv/lib/python3.10/site-packages/django/utils/functional.py”, line 47, in get
res = instance.dict[self.name] = self.func(instance)
File “/Applications/Training/Project_Amplify/venv/lib/python3.10/site-packages/django/urls/resolvers.py”, line 711, in urlconf_module
return import_module(self.urlconf_name)
File “/Users/Kiran.Thota/.pyenv/versions/3.10.2/lib/python3.10/importlib/init.py”, line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File “”, line 1050, in _gcd_import
File “”, line 1027, in _find_and_load
File “”, line 1006, in _find_and_load_unlocked
File “”, line 688, in _load_unlocked
File “”, line 883, in exec_module
File “”, line 241, in _call_with_frames_removed
File “/Applications/Training/Project_Amplify/quiz/quiz/urls.py”, line 21, in
from PyQuiz import views
File “/Applications/Training/Project_Amplify/quiz/PyQuiz/views.py”, line 3, in
from .forms import UserUpdateForm, profileUpdateForm, UserLoginForm, UserRegisterForm
File “/Applications/Training/Project_Amplify/quiz/PyQuiz/forms.py”, line 4, in
from allauth.account.forms import LoginForm
File “/Applications/Training/Project_Amplify/venv/lib/python3.10/site-packages/allauth/account/forms.py”, line 11, in
from allauth.account.internal import flows
File “/Applications/Training/Project_Amplify/venv/lib/python3.10/site-packages/allauth/account/internal/init.py”, line 1, in
from allauth.account.internal import flows
File “/Applications/Training/Project_Amplify/venv/lib/python3.10/site-packages/allauth/account/internal/flows/init.py”, line 1, in
from allauth.account.internal.flows import (
File “/Applications/Training/Project_Amplify/venv/lib/python3.10/site-packages/allauth/account/internal/flows/email_verification.py”, line 9, in
from allauth.account.models import EmailAddress
File “/Applications/Training/Project_Amplify/venv/lib/python3.10/site-packages/allauth/account/models.py”, line 23, in
class EmailAddress(models.Model):
File “/Applications/Training/Project_Amplify/venv/lib/python3.10/site-packages/django/db/models/base.py”, line 134, in new
raise RuntimeError(
RuntimeError: Model class allauth.account.models.EmailAddress doesn’t declare an explicit app_label and isn’t in an application in INSTALLED_APPS.
Below is the code:
forms.py
from django import forms
from django.contrib.auth.forms import UserCreationForm, UserChangeForm
from .models import User, Profile, Address
from allauth.account.forms import LoginFormclass CustomCreationForm(UserCreationForm):
class Meta: model = User fields = ("username", "email") app_label = "PyQuiz"
class CustomUserChangeForm(UserChangeForm):
class Meta: model = User field = ("username", "email") app_label = "PyQuiz"
class UserRegisterForm(UserCreationForm):
class Meta: model = User fields = ["name", "email", "password1", "password2"] app_label = "PyQuiz"
class UserUpdateForm(forms.ModelForm):
class Meta: model = User fields = ["name", "email"] app_label = "PyQuiz"
class profileUpdateForm(forms.ModelForm):
class Meta: model = Profile fields = ["address", "image"] app_label = "PyQuiz"
class UserLoginForm(LoginForm):
email = forms.EmailField(),class Meta: model = User feilds = ["email", "password"] app_label = "PyQuiz"
class EmailAddress(LoginForm):
class Meta: app_label = "PyQuiz"
models.py
from django.db import models
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager, PermissionsMixin # User
from django.utils import timezonefrom django.db.models.signals import post_save
from django.dispatch import receiver
from PIL import ImageCreate your models here.
class Address(models.Model):
name = models.CharField(max_length=30)
address = models.CharField(max_length=50)
city = models.CharField(max_length=60, default=“”)
state = models.CharField(max_length=30, default=“”)
postcode = models.CharField(max_length=6, default=“”)
country = models.CharField(max_length=50)class Meta: verbose_name = "Address" verbose_name_plural = " Address" app_label = "PyQuiz" def __str__(self): return self.name
class UserManager(BaseUserManager):
def _create_user(self, email, password, is_staff, is_superuser, **extra_fields): if not email: raise ValueError("Users must have an email address") now = timezone.now() email = self.normalize_email(email) user = self.model( email = email, is_staff = is_staff, is_active = True, is_superuser = is_superuser, last_login = now, date_joined= now, **extra_fields ) user.set_password(password) user.save(using=self._db) return user def create_user(self, email, password, **extra_fields): return self._create_user(email, password, True, True, **extra_fields) def create_superuser(self, email, password, **extra_fields): user = self._create_user(email, password, True, True, **extra_fields) user.save(using= self._db) return user class Meta: app_label = "PyQuiz"
class User(AbstractBaseUser, PermissionsMixin):
email = models.EmailField(max_length=254, unique=True)
name = models.CharField(max_length=254, null= True, blank= True)
user_name = models.CharField(max_length=254, null=True, blank=True)
is_staff = models.BooleanField(default=False)
is_superuser = models.BooleanField(default=False)
is_active = models.BooleanField(default=True)
last_login = models.DateTimeField(null=True, blank=True)
date_joined = models.DateTimeField(auto_now_add=True)USERNAME_FIELD = "email" EMAIL_FIELD = "email" REQUIRED_FIELDS = [] objects = UserManager() def get_absolute_url(self): return "/users/%i/" % (self.pk)
class Profile(models.Model):
user = models.OneToOneField(User, unique=True, on_delete=models.CASCADE, default=None)
address = models.CharField(max_length=254, null=True, blank=True)
image = models.ImageField(default=“default.jpg”, upload_to=“profile_pics”)def __str__(self): return f"{self.user.name} Profile" def save(self, *args, **kwargs): super.save(*args, **kwargs)
@receiver(post_save, sender= User)
def create_user_profile(sender, instance, created, **kwargs):
if created:
Profile.objects.create(user=instance)@receiver(post_save, sender=User)
def save_user_profile(sender, instance, **kwards):
instance.profile.save()
setting.py
Application definition
INSTALLED_APPS = [
‘PyQuiz.apps.PyquizConfig’,
‘django.contrib.admin’,
‘django.contrib.auth’,
‘django.contrib.contenttypes’,
‘django.contrib.sessions’,
‘django.contrib.messages’,
‘django.contrib.staticfiles’,
# ‘allauth.account’,
]
Thanks
Kiran