前提### 実現したいこと
ローカル環境内でログイン認証ページ後別のHTMLページを開きたいと考えてます。
ログインページでの認証はできておりリダイレクト後のページがPage not found (404)となります。
発生している問題・エラーメッセージ
Request Method: GET
Request URL: https://127.0.0.1:8000/mgtask.html/
Using the URLconf defined in pj_login.urls, Django tried these URL patterns, in this order:
admin/
mgtask/
[name='index']
login/ [name='login']
logout/ [name='logout']
password_change/ [name='password_change']
password_change/done/ [name='password_change_done']
password_reset/ [name='password_reset']
password_reset/done/ [name='password_reset_done']
reset/<uidb64>/<token>/ [name='password_reset_confirm']
reset/done/ [name='password_reset_complete']
The current path, mgtask.html/, didn’t match any of these.
該当のソースコード
*******************************************************settings.py
Django settings for pj_login project. Generated by 'django-admin startproject' using Django 3.0.2. For more information on this file, see https://docs.djangoproject.com/en/3.0/topics/settings/ For the full list of settings and their values, see https://docs.djangoproject.com/en/3.0/ref/settings/ """ 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 = 'v0h+s=#9_a^gxs+7=oto*nv=i+7x0_72___8s)sxlhi#sx1f9*' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True ALLOWED_HOSTS = ['*'] # Application definition INSTALLED_APPS = [ 'registration', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'sslserver', ] 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 = 'pj_login.urls' TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [], '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 = 'pj_login.wsgi.application' # 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'), } } # 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 = 'ja' 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/' EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' LOGIN_URL = "/login/" LOGIN_REDIRECT_URL = "/mgtask.html/" LOGOUT_REDIRECT_URL = "/login/" # 暗号化されたhttpsを使うようにする #SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') #SECURE_SSL_REDIRECT = False #SESSION_COOKIE_SECURE = True #CSRF_COOKIE_SECURE = True
*********************************************************views.py
from django.shortcuts import render from django.views.generic import TemplateView class TaskView(TemplateView): template_name = "mgtask.html"
************************************************************urls.py
from django.contrib import admin from django.urls import path, include from django.contrib.auth.decorators import login_required from django.views.generic import TemplateView index_view = TemplateView.as_view(template_name="registration/index.html") urlpatterns = [ path('admin/', admin.site.urls), path('mgtask/', include("registration.urls")), path("", login_required(index_view), name="index"), path('', include("django.contrib.auth.urls")), ]
********************************************************app内urls
from django.contrib import admin from django.urls import path, include from django.contrib.auth.decorators import login_required from django.views.generic import TemplateView from .views import TaskView index_view = TemplateView.as_view(template_name="registration/index.html") urlpatterns = [ path('mgtask/', TaskView.as_view(), name="mgtask"), path('admin/', admin.site.urls), path("", login_required(index_view), name="index"), path('', include("django.contrib.auth.urls")), ]
階層
pj_login pj_login _pycache __init__ asagi urlswsgi registration _pycache_ migrations templates registration index.html login.html _form.html base.html mgtask.html __init__ admin apps models tests urls views
python 3.10.4 django 4.0.5
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/07/19 07:36
2022/07/19 07:44 編集
2022/07/20 02:55