change the naming of the urls like for the login from "login" to something like "login_page" because you are causing a clash in the views.py code since you are importing login and your url name is the same ....rename the logout too
hope that helps On Mon, Aug 7, 2023 at 2:40 PM AKHIL KORE <[email protected]> wrote: > I got the error in my below existings django files. Please solve this > error and check all below files code. > > File "C:\django2pm\myvenv\lib\site-packages\django\urls\resolvers.py", > line 725, in url_patterns > raise ImproperlyConfigured(msg.format(name=self.urlconf_name)) from e > django.core.exceptions.ImproperlyConfigured: The included URLconf > 'registration1.urls' does not appear to have any patterns in it. If you see > the 'urlpatterns' variable with valid patterns in the file then the issue > is probably caused by a circular import. > > registration1/settings.py > ------------------------ > from pathlib import Path > > # Build paths inside the project like this: BASE_DIR / 'subdir'. > BASE_DIR = Path(__file__).resolve().parent.parent > > > # Quick-start development settings - unsuitable for production > # See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/ > > # SECURITY WARNING: keep the secret key used in production secret! > SECRET_KEY = > 'django-insecure-bz1vja=h9vcnl_=j&n0!-1*+t(j(fn!qzzx5wgy_nu_f-i5c%t' > > # SECURITY WARNING: don't run with debug turned on in production! > DEBUG = True > > ALLOWED_HOSTS = [] > > # Application definition > > INSTALLED_APPS = [ > 'django.contrib.admin', > 'django.contrib.auth', > 'django.contrib.contenttypes', > 'django.contrib.sessions', > 'django.contrib.messages', > 'django.contrib.staticfiles', > 'app1', > 'crispy_forms', > 'crispy_bootstrap5', > 'rest_framework', > ] > > 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 = 'registration1.urls' > > TEMPLATES = [ > { > 'BACKEND': 'django.template.backends.django.DjangoTemplates', > 'DIRS': ['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', > ], > }, > }, > ] > > WSGI_APPLICATION = 'registration1.wsgi.application' > > > # Database > # https://docs.djangoproject.com/en/4.1/ref/settings/#databases > > DATABASES = { > 'default': { > 'ENGINE': 'django.db.backends.mysql', > 'NAME': 'user_registration', > 'USER': 'shamiit_database', > 'PASSWORD': 'shamiit123', > 'HOST': '183.83.187.12', > 'PORT': '6013', > } > } > > > # Password validation > # > https://docs.djangoproject.com/en/4.1/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/4.1/topics/i18n/ > > LANGUAGE_CODE = 'en-us' > > TIME_ZONE = 'UTC' > > USE_I18N = True > > USE_TZ = True > > > # Static files (CSS, JavaScript, Images) > # https://docs.djangoproject.com/en/4.1/howto/static-files/ > > STATIC_URL = 'static/' > LOGIN_URL = '/login/' > > # Default primary key field type > # https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field > > DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' > > CRISPY_TEMPLATE_PACK = 'bootstrap5' > CRISPY_ALLOWED_TEMPLATE_PACKS = 'bootstrap5' > > # Add this line at the bottom of the file > AUTH_USER_MODEL = 'app1.CustomUser' > > EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' > EMAIL_HOST = 'smtp.gmail.com' # Change to your email provider's SMTP > server > EMAIL_PORT = 587 # Change to your email provider's port > EMAIL_USE_TLS = True # Change to True if your email provider requires TLS > EMAIL_HOST_USER = '[email protected]' # Your email address > EMAIL_HOST_PASSWORD = 'ngxfvpwoasfumnkc' # Your email password > > from django.utils.translation import gettext_lazy as _ > > PASSWORD_RESET_SUBJECT = _('Password Reset Request') > PASSWORD_RESET_EMAIL_BODY = _( > 'You have requested a password reset. Follow the link below to reset > your password:\n\n' > '{protocol}://{domain}{url}\n\n' > 'If you did not request this reset, please ignore this email.\n' > 'Your username, in case you\'ve forgotten: {username}' > ) > > registration1/urls.py > --------------------- > from django.contrib import admin > from django.urls import path, include > > urlpatterns = [ > path('admin/', admin.site.urls), > path('', include('app1.urls')), > ] > > app1/models.py > ------------- > from django.contrib.auth.models import AbstractUser > from django.db import models > > # Custom user model > class CustomUser(AbstractUser): > firstname = models.CharField(max_length=50) > lastname = models.CharField(max_length=50) > > def __str__(self): > return self.username > > # UserProfile model using the custom user model > class UserProfile(models.Model): > user = models.OneToOneField(CustomUser, on_delete=models.CASCADE, > related_name='profile') > email = models.EmailField() > password = models.CharField(max_length=128) > created_date = models.DateField(auto_now_add=True) > created_time = models.TimeField(auto_now_add=True) > > def __str__(self): > return f"{self.user.username}" > > app1/serializers.py > ------------------ > from rest_framework import serializers > from .models import CustomUser, UserProfile > from django.contrib.auth.models import User > > class CustomUserSerializer(serializers.ModelSerializer): > class Meta: > model = CustomUser > fields = ['id', 'firstname', 'lastname'] > > class UserProfileSerializer(serializer.ModelSerializer): > class Meta: > model = UserProfile > fields = '__all__' > > app1/forms.py > ------------ > from django import forms > from django.contrib.auth.forms import UserCreationForm, AuthenticationForm > from .models import UserProfile > from .models import CustomUser > from django.contrib.auth.forms import PasswordResetForm > > > class SignupForm(forms.ModelForm): > password1 = forms.CharField(label='Password', > widget=forms.PasswordInput) > password2 = forms.CharField(label='Confirm Password', > widget=forms.PasswordInput) > > class Meta: > model = CustomUser > fields = ['username', 'firstname', 'lastname', 'email', > 'password1', 'password2'] > > class LoginForm(AuthenticationForm): > class Meta: > model = CustomUser > fields = ['username', 'password'] > > class CustomPasswordResetForm(PasswordResetForm): > email = forms.EmailField( > label="Email", > widget=forms.EmailInput(attrs={'class': 'form-control'}), > ) > > password1 = forms.CharField( > label="New Password", > widget=forms.PasswordInput(attrs={'class': 'form-control'}), > ) > > password2 = forms.CharField( > label="Confirm New Password", > widget=forms.PasswordInput(attrs={'class': 'form-control'}), > ) > > def clean_password2(self): > password1 = self.cleaned_data.get("password1") > password2 = self.cleaned_data.get("password2") > if password1 and password2 and password1 != password2: > raise forms.ValidationError("Passwords do not match.") > return password2 > > app1/views.py > ------------ > from django.shortcuts import render, HttpResponse, redirect > from django.contrib.auth import authenticate, login, logout > from django.contrib.auth.decorators import login_required > from .models import UserProfile > from django.contrib.auth.forms import SetPasswordForm > from django.contrib.auth.forms import PasswordResetForm > from .forms import SignupForm, LoginForm > from django.urls import reverse, reverse_lazy > from django.core.mail import send_mail > from django.conf import settings > from django.views.decorators.csrf import csrf_exempt > from django.contrib.auth.views import (PasswordResetView, > PasswordResetDoneView, PasswordResetConfirmView, > PasswordResetCompleteView) > > @login_required(login_url='login') > def HomePage(request): > return render(request, 'home.html') > > def SignupPage(request): > if request.method == "POST": > form = SignupForm(request.POST) > if form.is_valid(): > user = form.save(commit=False) > user.set_password(form.cleaned_data['password1']) > user.save() > return redirect('login') > else: > form = SignupForm() > return render(request, 'signup.html', {'form': form}) > > @csrf_exempt > def LoginPage(request): > if request.method == "POST": > form = LoginForm(request, request.POST) > if form.is_valid(): > username = form.cleaned_data['username'] > password = form.cleaned_data['password'] > user = authenticate(request, username=username, > password=password) > if user is not None: > login(request, user) > return redirect('home') > else: > return HttpResponse("Username or Password is incorrect!!") > else: > form = LoginForm() > return render(request, 'login.html', {'form': form}) > > > def LogoutPage(request): > logout(request) > return redirect('login') > > class CustomPasswordResetView(PasswordResetView): > form_class = PasswordResetForm > template_name = 'password_reset_form.html' > email_template_name = 'password_reset_email.html' > success_url = reverse_lazy('password_reset_done') > > class CustomPasswordResetDoneView(PasswordResetDoneView): > template_name = 'password_reset_done.html' > > class CustomPasswordResetConfirmView(PasswordResetConfirmView): > form_class = SetPasswordForm > template_name = 'password_reset_confirm.html' > success_url = reverse('password_reset_complete') > > class CustomPasswordResetCompleteView(PasswordResetCompleteView): > template_name = 'password_reset_complete.html' > > > app1/urls.py > ----------- > from django.urls import path > from . import views > from django.contrib.auth import views as auth_views > > urlpatterns = [ > path('', views.SignupPage, name='signup'), > path('login/', views.LoginPage, name='login'), > path('home/', views.HomePage, name='home'), > path('logout/', views.LogoutPage, name='logout'), > path('password_reset/', views.CustomPasswordResetView.as_view(), > name='password_reset'), > path('password_reset/done/', > views.CustomPasswordResetDoneView.as_view(), name='password_reset_done'), > path('reset/<uidb64>/<token>/', > views.CustomPasswordResetConfirmView.as_view(), > name='password_reset_confirm'), > path('reset/done/', views.CustomPasswordResetCompleteView.as_view(), > name='password_reset_complete'), > ] > > -- > 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 [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/CAB11hN_wiuACSUDa89UbOYuyNdVzK2_KtAA48%3DWhkDROo3E2Qg%40mail.gmail.com > <https://groups.google.com/d/msgid/django-users/CAB11hN_wiuACSUDa89UbOYuyNdVzK2_KtAA48%3DWhkDROo3E2Qg%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAMJ3z%3D3NNZtS%2BTev8Y2bDmf-%3DeCaoM1eFQEqLdPo3Q-gtBYPjw%40mail.gmail.com.

