前提・実現したいこと
Djangoにおいて発生したエラーを解消したい
該当する箇所がどこなのか分からず困っています
どなたかご教授頂けると幸いです
http://127.0.0.1:8000/polls/でエラーが発生
発生している問題・エラーメッセージ
error
1TypeError at /polls/ 2__init__() takes 1 positional argument but 2 were given 3Request Method: GET 4Request URL: http://127.0.0.1:8000/polls/ 5Django Version: 3.0.1 6Exception Type: TypeError 7Exception Value: 8__init__() takes 1 positional argument but 2 were given 9Exception Location: C:\Users\sa96t\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\handlers\base.py in _get_response, line 113 10Python Executable: C:\Users\sa96t\AppData\Local\Programs\Python\Python38-32\python.exe 11Python Version: 3.8.0 12Python Path: 13['C:\Users\sa96t\Desktop\Django\mysite', 14 'C:\Users\sa96t\AppData\Local\Programs\Python\Python38-32\python38.zip', 15 'C:\Users\sa96t\AppData\Local\Programs\Python\Python38-32\DLLs', 16 'C:\Users\sa96t\AppData\Local\Programs\Python\Python38-32\lib', 17 'C:\Users\sa96t\AppData\Local\Programs\Python\Python38-32', 18 'C:\Users\sa96t\AppData\Local\Programs\Python\Python38-32\lib\site-packages'] 19Server time: Sat, 11 Jan 2020 11:17:02 +0000 20 21Traceback Switch to copy-and-paste view 22C:\Users\sa96t\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\handlers\exception.py in inner 23 response = get_response(request) … 24▶ Local vars 25C:\Users\sa96t\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\handlers\base.py in _get_response 26 response = self.process_exception_by_middleware(e, request) … 27▶ Local vars 28C:\Users\sa96t\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\handlers\base.py in _get_response 29 response = wrapped_callback(request, *callback_args, **callback_kwargs) … 30▶ Local vars
該当のソースコード
該当する箇所が分からないが、該当しそうな箇所を記述しようと思います
polls/urls.py
1from django.urls import path 2 3from . import views 4 5app_name = 'polls' 6 7urlpatterns = [ 8 #path('', views.index, name='index'), 9 #path('<int:question_id>/', views.detail, name='detail'), 10 #path('<int:question_id>/result', views.results, name='result'), 11 path('<int:question_id>/vote/', views.vote, name='vote'), 12 13 path('', views.IndexView, name='index'), 14 path('<int:pk>/', views.DetailView.as_view(), name='detail'), 15 path('<int:pk>/results/', views.ResultsView.as_view(), name='results'), 16]
polls/views.py
1def vote(request, question_id): 2 return HttpResponse("You're voting on question %s." % question_id) 3 4class IndexView(generic.ListView): 5 template_name = 'polls/index.html' 6 context_object_name = 'latest_question_list' 7 8 def get_queryset(self): 9 #return Question.objects.order_by('-pub_date')[:5] 10 11 return Question.objects.filter( 12 pub_date__lte = timezone.now() 13 ).order_by('-pub_date')[:5] 14 15class DetailView(generic.DetailView): 16 model = Question 17 template_name = 'polls/detail.html' 18 19 def get_queryset(self): 20 return Question.objects.filter(pub_date__lte=timezone.now()) 21 22class ResultsView(generic.DetailView): 23 model = Question 24 template_name = 'polls/results.html'
polls/templates/polls/index.html
1{% load static %} 2 3<link rel="stylesheet" type="text/css" href="{% static 'polls/style.css' %}"> 4 5{% if latest_question_list %} 6 <ul> 7 {% for question in latest_question_list %} 8 <li><a href="{% url 'polls:detail' question_id %}">{{ question.question_text }}</a>></li> 9 {% endfor %} 10 </ul> 11{% else %} 12 <p>No polls are available</p> 13{% endif %}
試したこと
http://127.0.0.1:8000/polls/0/ -> Page Not Found
http://127.0.0.1:8000/polls/1/ -> 表示可能
http://127.0.0.1:8000/polls/0/results/ -> Page Not Found
http://127.0.0.1:8000/polls/1/results/ -> 表示可能
補足情報(FW/ツールのバージョンなど)
以下のサイトを初めから実践しており、その6まで
参考資料
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2020/01/12 01:21