エラーを見るとpolls/ post_int/は記載されているがpolls/post_intは記載されていないとなってしまいます。polls/とpost_int/の間にスペースが勝手に入力されてしまうため、404エラーになっているのではないかと考えています。スペースが勝手に入力されてしまう現象はなぜ起こっているのかを教えていただけないでしょうか。
mysite_soccer/mysite_soccer/urls.py
python
1from django.contrib import admin 2from django.urls import path,include 3 4urlpatterns = [ 5 path('admin/', admin.site.urls), 6 path('polls/', include('polls.urls')), 7]
mysite_soccer/polls/urls.py
python
1from django.urls import path 2 3from . import views 4 5urlpatterns = [ 6 path('', views.index, name='index'), 7 path('post_int/',views.index), 8]
mysite_soccer/polls/templates/polls/index.html
html
1<html> 2 <body> 3 <form action="post_int" method="post"> 4 <div> 5 <label>1つ目の数字</label> 6 <input type="int" name="int_A" id="int_A" value="{{ int_A }}"> 7 </div> 8 <div> 9 <label>2つ目の数字</label> 10 <input type="int" name="int_B" id="int_B" value="{{ int_B }}"> 11 </div> 12 <div> 13 <label for="message">テスト</label> 14 <textarea id="message" name="message">{{ message }}</textarea> 15 </div> 16 <input type="submit" value="送信"> 17 </form> 18 </body> 19</html>
mysite_soccer/polls/views.py
python
1from django.shortcuts import render 2 3# Create your views here. 4from django.http import HttpResponse 5from django.template import loader 6from django.views import View 7 8 9def index(request): 10 template = loader.get_template('polls/index.html') 11 return HttpResponse(template.render()) 12 13class indexView(View): 14 def get(self,request,*args,**kwargs): 15 context = { 16 "message":"Hello World!", 17 } 18 return render(request,"polls/index.html",context) 19 20 def post_int(self,request,*args,**kwargs): 21 context={ 22 "int_A":request.POST["int_A"], 23 "int_B":request.POST["int_B"], 24 } 25 return render(request,'polls/index.html',context) 26index = indexView.as_view()
mysite_soccer/mysite_soccer/settings.py
python
1""" 2Django settings for mysite_soccer project. 3 4Generated by 'django-admin startproject' using Django 3.1.6. 5 6For more information on this file, see 7https://docs.djangoproject.com/en/3.1/topics/settings/ 8 9For the full list of settings and their values, see 10https://docs.djangoproject.com/en/3.1/ref/settings/ 11""" 12 13from pathlib import Path 14 15# Build paths inside the project like this: BASE_DIR / 'subdir'. 16BASE_DIR = Path(__file__).resolve().parent.parent 17 18 19# Quick-start development settings - unsuitable for production 20# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/ 21 22# SECURITY WARNING: keep the secret key used in production secret! 23SECRET_KEY = '-qfqdy2c7wxf)w89e%)%q@xcrqgl8ej-)jdpj!nt6(*y&9tjtq' 24 25# SECURITY WARNING: don't run with debug turned on in production! 26DEBUG = True 27 28ALLOWED_HOSTS = [] 29 30 31# Application definition 32 33INSTALLED_APPS = [ 34 'polls.apps.PollsConfig', 35 'django.contrib.admin', 36 'django.contrib.auth', 37 'django.contrib.contenttypes', 38 'django.contrib.sessions', 39 'django.contrib.messages', 40 'django.contrib.staticfiles', 41] 42 43MIDDLEWARE = [ 44 'django.middleware.security.SecurityMiddleware', 45 'django.contrib.sessions.middleware.SessionMiddleware', 46 'django.middleware.common.CommonMiddleware', 47 'django.contrib.auth.middleware.AuthenticationMiddleware', 48 'django.contrib.messages.middleware.MessageMiddleware', 49 'django.middleware.clickjacking.XFrameOptionsMiddleware', 50 'django.middleware.csrf.CsrfViewMiddleware', 51] 52 53ROOT_URLCONF = 'mysite_soccer.urls' 54 55TEMPLATES = [ 56 { 57 'BACKEND': 'django.template.backends.django.DjangoTemplates', 58 'DIRS': [], 59 'APP_DIRS': True, 60 'OPTIONS': { 61 'context_processors': [ 62 'django.template.context_processors.debug', 63 'django.template.context_processors.request', 64 'django.contrib.auth.context_processors.auth', 65 'django.contrib.messages.context_processors.messages', 66 ], 67 }, 68 }, 69] 70 71WSGI_APPLICATION = 'mysite_soccer.wsgi.application' 72 73 74# Database 75# https://docs.djangoproject.com/en/3.1/ref/settings/#databases 76 77DATABASES = { 78 'default': { 79 'ENGINE': 'django.db.backends.sqlite3', 80 'NAME': BASE_DIR / 'db.sqlite3', 81 } 82} 83 84 85# Password validation 86# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators 87 88AUTH_PASSWORD_VALIDATORS = [ 89 { 90 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 91 }, 92 { 93 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 94 }, 95 { 96 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 97 }, 98 { 99 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 100 }, 101] 102 103 104# Internationalization 105# https://docs.djangoproject.com/en/3.1/topics/i18n/ 106 107LANGUAGE_CODE = 'en-us' 108 109TIME_ZONE = 'UTC' 110 111USE_I18N = True 112 113USE_L10N = True 114 115USE_TZ = True 116 117APPEND_SLASH = False 118 119 120# Static files (CSS, JavaScript, Images) 121# https://docs.djangoproject.com/en/3.1/howto/static-files/ 122 123STATIC_URL = '/static/' 124
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/03/18 02:35
2021/03/18 12:07
2021/03/19 03:21
2021/03/19 03:22