前提・実現したいこと
djangoを用いてWEBアプリケーションを作っている途中でTypeError: 'NoneType' object is not callableが出てしまった。
エラーメッセージ
http://127.0.0.1:8000/にはアクセスでき、http://127.0.0.1:8000/inquiry/のページに行くとTypeError: 'NoneType' object is not callableが起こってしまう
Django version 3.1.1, using settings 'private_diary.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CTRL-BREAK. 2020-09-06 13:57:43,838 [INFO] C:\Users\rikuw\venv_private_diary\lib\site-packages\django\core\servers\basehttp.py(Line:157) "GET / HTTP/1.1" 200 4400 2020-09-06 13:57:43,859 [WARNING] C:\Users\rikuw\venv_private_diary\lib\site-packages\django\core\servers\basehttp.py(Line:157) "GET /static/css/mystyle.css HTTP/1.1" 404 1671 2020-09-06 13:57:53,117 [ERROR] C:\Users\rikuw\venv_private_diary\lib\site-packages\django\utils\log.py(Line:224) Internal Server Error: /inquiry/ Traceback (most recent call last): File "C:\Users\rikuw\venv_private_diary\lib\site-packages\django\core\handlers\exception.py", line 47, in inner response = get_response(request) File "C:\Users\rikuw\venv_private_diary\lib\site-packages\django\core\handlers\base.py", line 179, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "C:\Users\rikuw\venv_private_diary\lib\site-packages\django\views\generic\base.py", line 70, in view return self.dispatch(request, *args, **kwargs) File "C:\Users\rikuw\venv_private_diary\lib\site-packages\django\views\generic\base.py", line 98, in dispatch return handler(request, *args, **kwargs) File "C:\Users\rikuw\venv_private_diary\lib\site-packages\django\views\generic\edit.py", line 133, in get return self.render_to_response(self.get_context_data()) File "C:\Users\rikuw\venv_private_diary\lib\site-packages\django\views\generic\edit.py", line 66, in get_context_data kwargs['form'] = self.get_form() File "C:\Users\rikuw\venv_private_diary\lib\site-packages\django\views\generic\edit.py", line 33, in get_form return form_class(**self.get_form_kwargs()) TypeError: 'NoneType' object is not callable 2020-09-06 13:57:53,120 [ERROR] C:\Users\rikuw\venv_private_diary\lib\site-packages\django\core\servers\basehttp.py(Line:157) "GET /inquiry/ HTTP/1.1" 500 82013
urls.py
python
1from django.urls import path 2 3from . import views 4 5 6app_name = 'diary' 7urlpatterns = [ 8 path('', views.IndexView.as_view(), name="index"), 9 path('inquiry/', views.InquiryView.as_view(), name="inquiry"), 10] 11
forms.py
from django import forms class InquiryForm(forms.Form): name = forms.CharField(label='お名前', max_length=30) email = forms.EmailField(label='メールアドレス') title = forms.CharField(label='タイトル', max_length=30) message = forms.CharField(label='メッセージ', widget=forms.Textarea) def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.fields['name'].widget.attrs['class'] = 'form-control col-9' self.fields['name'].widget.attrs['placeholder'] = 'お名前をここに入力してください。' self.fields['email'].widget.attrs['class'] = 'form-control col-11' self.fields['email'].widget.attrs['placeholder'] = 'メールアドレスをここに入力してください。' self.fields['title'].widget.attrs['class'] = 'form-control col-11' self.fields['title'].widget.attrs['placeholder'] = 'タイトルをここに入力してください。' self.fields['message'].widget.attrs['class'] = 'form-control col-12' self.fields['message'].widget.attrs['placeholder'] = 'メッセージをここに入力してください。'
###views.py
from django.shortcuts import render # Create your views here. from django.views import generic from.forms import InquiryForm class IndexView(generic.TemplateView): template_name = "index.html" class InquiryView(generic.FormView): template_name = "inquiry.html" from_class = InquiryForm
補足情報(FW/ツールのバージョンなど)
windows
Python 3.8.5
python -m django --version
3.1.1
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/09/07 02:54