title: DjangoRelatedObjectDoesNotExist at /profile/
body: <p>I've been through in similar topics for days for a possible solution, however none of them solved my issue which seems pretty simple to me but I stucked on this error right after I created a user: RelatedObjectDoesNotExist at /profile/
  <a href="https://i.stack.imgur.com/6YMkJ.png" rel="nofollow noreferrer">Error I'm getting</a></p>
  <p>I know there must be something missing in my singlas.py which does not create the Profile after creation of a User but I'm lost in solutions after tried many. Any help will make my day after long frustration period;</p>
  <p>In project main folder; settings.py</p>
  <pre><code>import os
  
  # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
  BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  
  
  # Quick-start development settings - unsuitable for production
  # See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
  
  # SECURITY WARNING: keep the secret key used in production secret!
  SECRET_KEY = '7aa*ng4p*o!9h4%hyfgu=9xy69aumg6hzbz3g)1mf^4!+gi+e0'
  
  # SECURITY WARNING: don't run with debug turned on in production!
  DEBUG = True
  
  ALLOWED_HOSTS = []
  
  # Application definition
  
  DEFAULT_APPS = [
      'django.contrib.admin',
      'django.contrib.auth',
      'django.contrib.contenttypes',
      'django.contrib.sessions',
      'django.contrib.messages',
      'django.contrib.staticfiles',
      'apps.daily_brief',
      'apps.users',
      'apps.crm',
  ]
  
  THIRD_PARTY_APPS = [
      'crispy_forms',
      'django_cleanup',
      'social_django',
  ]
  
  LOCAL_APPS = []
  
  INSTALLED_APPS = DEFAULT_APPS + THIRD_PARTY_APPS + LOCAL_APPS
  
  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',
      'social_django.middleware.SocialAuthExceptionMiddleware',
  ]
  
  ROOT_URLCONF = 'project_folder.urls'
  
  TEMPLATES = [
      {
          'BACKEND': 'django.template.backends.django.DjangoTemplates',
          'DIRS': [BASE_DIR + '/templates/',],
          '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',
  
                  'social_django.context_processors.backends', 
                  'social_django.context_processors.login_redirect',
              ],
          },
      },
  ]
  
  AUTHENTICATION_BACKENDS = (
              'social_core.backends.facebook.FacebookOAuth2',
              'social_core.backends.twitter.TwitterOAuth',
              'social_core.backends.github.GithubOAuth2',
  
              'django.contrib.auth.backends.ModelBackend',
          )
  
  WSGI_APPLICATION = 'project_folder.wsgi.application'
  
  
  
  # Password validation
  # https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
  
  AUTH_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',
      },
  ]
  
  
  # Internationalization
  # https://docs.djangoproject.com/en/3.0/topics/i18n/
  
  LANGUAGE_CODE = 'en-us'
  
  TIME_ZONE = 'UTC'
  
  USE_I18N = True
  
  USE_L10N = True
  
  USE_TZ = True
  
  
  # Static files (CSS, JavaScript, Images)
  # https://docs.djangoproject.com/en/3.0/howto/static-files/
  
  STATIC_URL = '/static/'
  STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'),)
  STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
  
  MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
  MEDIA_URL = '/media/'
  
  try:
      from project_folder.local_settings import *
  except ImportError:
      print('local_settings error')
      pass
  
  CRISPY_TEMPLATE_PACK = 'bootstrap4'
  
  LOGIN_REDIRECT_URL = 'daily_brief_home'
  
  LOGIN_URL = 'login'
  
  SOCIAL_AUTH_FACEBOOK_KEY = '****************'  # Removed for security purposes but there was a code
  SOCIAL_AUTH_FACEBOOK_SECRET = '***************'  # Removed for security purposes but there was a code
  
  
  EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
  EMAIL_HOST = 'smtp.gmail.com'
  EMAIL_PORT = 587
  EMAIL_USE_TLS = True
  EMAIL_HOST_USER = os.environ['DB_USER']  
  EMAIL_HOST_PASSWORD = os.environ['DB_PASS']  
  </code></pre>
  <p>project main folder local_settings.py</p>
  <pre><code>import os
  
  # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
  BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  
  # Database
  # https://docs.djangoproject.com/en/3.0/ref/settings/#databases
  
  DATABASES = {
      'default': {
          'ENGINE': 'django.db.backends.sqlite3',
          'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
      }
  }
  </code></pre>
  <p>project main folder urls.py</p>
  <pre><code>from django.contrib import admin
  from django.urls import path, include
  
  urlpatterns = [
      path('admin/', admin.site.urls),
  
      path('', include('apps.daily_brief.urls')),
  
      path('', include('apps.users.urls')),
  
      path('', include('apps.crm.urls')),
  ]
  
  # if settings.DEBUG: 
  #     urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
  </code></pre>
  <p>users app admin.py</p>
  <pre><code>from django.contrib import admin
  from .models import Profile 
  
  admin.site.register(Profile) 
  </code></pre>
  <p>users app apps.py</p>
  <pre><code>from django.apps import AppConfig
  
  class UsersConfig(AppConfig):
      name = 'users'
  
      def ready(self):
          import users.signals
  </code></pre>
  <p>users app forms.py</p>
  <pre><code>from django import forms
  from django.contrib.auth.models import User
  from django.contrib.auth.forms import UserCreationForm
  from .models import Profile  
  
  class UserRegisterForm(UserCreationForm):  
      email = forms.EmailField()  
      
      class Meta:  
          model = User  
          fields = ['username', 'email', 'password1', 'password2']  
  
  class UserUpdateForm(forms.ModelForm):  
      email = forms.EmailField()
  
      class Meta:
          model = User
          fields = ['username','email']
  
  class ProfileUpdateForm(forms.ModelForm):  
      class Meta:
          model = Profile
          fields = ['image']
  </code></pre>
  <p>users app models.py</p>
  <pre><code>from django.db import models
  from django.contrib.auth.models import User  
  from PIL import Image  
  
  class Profile(models.Model):  
      user = models.OneToOneField(User, on_delete=models.CASCADE)  
      image = models.ImageField(default='default.jpg', upload_to='profile_pics')  
  
      def __str__(self):  
          return f'{self.user.username} Profile'  
  
      def save(self, *args, **kwargs):  
          super().save(*args, **kwargs)  
  
          img = Image.open(self.image.path)  
          if img.height &gt; 300 or img.width &gt; 300: 
              output_size = (300, 300) 
              img.thumbnail(output_size) 
              img.save(self.image.path)
  </code></pre>
  <p>users app signals.py</p>
  <pre><code>from django.db.models.signals import post_save  
  from django.contrib.auth.models import User  
  from django.dispatch import receiver  
  from .models import Profile  
  
  @receiver(post_save, sender=User)  
  def create_profile(sender, instance, created, **kwargs):  
      if created:  
          Profile.objects.create(user=instance)
  
  @receiver(post_save, sender=User)
  def save_profile(sender, instance, **kwargs):
      instance.profile.save()  
  </code></pre>
  <p>users app urls.py</p>
  <pre><code>from django.urls import path, include
  from .views import register, profile
  from django.contrib.auth import views as auth_views
  from django.conf import settings  
  from django.conf.urls.static import static  
  from django.views.static import serve  
  
  urlpatterns = [
      path('register/', register, name='register'),
      path('profile/', profile, name='profile'),
      path('login/', auth_views.LoginView.as_view(template_name='users/login.html'), name='login'),
      path('logout/', auth_views.LogoutView.as_view(template_name='users/logout.html'), name='logout'),
      path('oauth/', include('social_django.urls', namespace='social')),
      path('password_reset/', auth_views.PasswordResetView.as_view(template_name='users/password_reset.html'), name='password_reset'), 
      path('password_reset/done', auth_views.PasswordResetDoneView.as_view(template_name='users/password_reset_done.html'), name='password_reset_done'),
      path('password_reset_confirm/&lt;uidb64&gt;/&lt;token&gt;/', auth_views.PasswordResetConfirmView.as_view(template_name='users/password_reset_confirm.html'), name='password_reset_confirm'),
      path('password_reset_complete', auth_views.PasswordResetCompleteView.as_view(template_name='users/password_reset_complete.html'), name='password_reset_complete'),
  ]
  
  if settings.DEBUG: 
      urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
  </code></pre>
  <p>users app views.py</p>
  <pre><code>from django.shortcuts import render, redirect
  # from django.contrib.auth.forms import UserCreationForm
  from django.contrib import messages
  from .forms import UserRegisterForm, UserUpdateForm, ProfileUpdateForm
  from django.contrib.auth.decorators import login_required
  from django.views.generic import TemplateView
  
  def register(request):
      if request.method == 'POST':
          form = UserRegisterForm(request.POST)  
          if form.is_valid():
              form.save() 
              username = form.cleaned_data.get('username')  
              messages.success(request, f'Account created for {username}!') 
              return redirect('login') 
      else:
          form = UserRegisterForm()  
      return render(request, 'users/register.html', {'form': form}) 
  
  
  @login_required  
  def profile(request):  
      if request.method == 'POST':
          u_form = UserUpdateForm(request.POST,  instance=request.user)
          p_form = ProfileUpdateForm(request.POST, request.FILES, instance=request.user.profile)
          if u_form.is_valid() and p_form.is_valid():
              u_form.save()
              p_form.save()
              messages.success(request, f'Your account has been updated!')  
              return redirect('profile')  
      else:
          u_form = UserUpdateForm(instance=request.user)
          p_form = ProfileUpdateForm(instance=request.user.profile)
      context = {'u_form': u_form, 'p_form': p_form}  
      return render(request, 'users/profile.html', context)  
  
  
  class SocialMediaLoginView(TemplateView):
      template_name = 'users/login.html'
  </code></pre>
  <p>In projects main folder and users app init.py is emtpy
  My directory mapping <a href="https://i.stack.imgur.com/Gq38U.png" rel="nofollow noreferrer">Directory mapping</a></p>