python django超入門という本を見ながら勉強しております。
その中で、いろいろとformを作っていました。
チェックボックスを作りたくて、本の通りしたつもりですが、コマンドプロンプトには件名の通りのエラーがでてしまい、原因が自分ではわかりません。。。
きちんとforms.pyには書いていると思うのすが、どうかどなたか教えていただければと思います。
宜しくお願いいたします。
forms.pyです↓
from django import forms class HelloForm(forms.Form): check=forms.BoolenField(label='Checkbox',required=False)
views.pyです↓
from django.shortcuts import render from django.http import HttpResponse from django.views.generic import TemplateView from .forms import HelloForm # Create your views here. class HelloView(TemplateView): def __init__(self): self.params={ 'title':'Hello', 'form':HelloForm(), 'result':None } def get(self,request): return render(request,'hello/index.html',self.params) def post(self,request): if('check'in request.POST): self.params['result']='Checked!!' else: self.params['result']='not checked...' self.params['form']=HelloForm(request.POST) return render(request,'hello/index.html',self.params)
index.htmlです↓
{% load static %} <!doctype html> <html lang="ja"> <head> <meta charset="utf-8"> <title>{{title}}</title> <link rel="stylesheet" type="text/css" href="{% static 'hello/css/style.css' %}" /> </head> <body> <h1>{{title}}</h1> <p>{{result|safe}}</p> <table> <form action="{% url 'index' %}" method="post"> {% csrf_token %} {{ form.as_p }} <tr><tb></tb><tb><input type="submit" value="click"></tb></tr> </form> </table> </body> </html>
エラー内容全ては下記の通りです。↓
Watching for file changes with StatReloader
Performing system checks... Exception in thread django-main-thread: Traceback (most recent call last): File "/opt/anaconda3/envs/myspace/lib/python3.7/threading.py", line 926, in _bootstrap_inner self.run() File "/opt/anaconda3/envs/myspace/lib/python3.7/threading.py", line 870, in run self._target(*self._args, **self._kwargs) File "/opt/anaconda3/envs/myspace/lib/python3.7/site-packages/django/utils/autoreload.py", line 53, in wrapper fn(*args, **kwargs) File "/opt/anaconda3/envs/myspace/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 117, in inner_run self.check(display_num_errors=True) File "/opt/anaconda3/envs/myspace/lib/python3.7/site-packages/django/core/management/base.py", line 395, in check include_deployment_checks=include_deployment_checks, File "/opt/anaconda3/envs/myspace/lib/python3.7/site-packages/django/core/management/base.py", line 382, in _run_checks return checks.run_checks(**kwargs) File "/opt/anaconda3/envs/myspace/lib/python3.7/site-packages/django/core/checks/registry.py", line 72, in run_checks new_errors = check(app_configs=app_configs) File "/opt/anaconda3/envs/myspace/lib/python3.7/site-packages/django/core/checks/urls.py", line 13, in check_url_config return check_resolver(resolver) File "/opt/anaconda3/envs/myspace/lib/python3.7/site-packages/django/core/checks/urls.py", line 23, in check_resolver return check_method() File "/opt/anaconda3/envs/myspace/lib/python3.7/site-packages/django/urls/resolvers.py", line 407, in check for pattern in self.url_patterns: File "/opt/anaconda3/envs/myspace/lib/python3.7/site-packages/django/utils/functional.py", line 48, in __get__ res = instance.__dict__[self.name] = self.func(instance) File "/opt/anaconda3/envs/myspace/lib/python3.7/site-packages/django/urls/resolvers.py", line 588, in url_patterns patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module) File "/opt/anaconda3/envs/myspace/lib/python3.7/site-packages/django/utils/functional.py", line 48, in __get__ res = instance.__dict__[self.name] = self.func(instance) File "/opt/anaconda3/envs/myspace/lib/python3.7/site-packages/django/urls/resolvers.py", line 581, in urlconf_module return import_module(self.urlconf_name) File "/opt/anaconda3/envs/myspace/lib/python3.7/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1006, in _gcd_import File "<frozen importlib._bootstrap>", line 983, in _find_and_load File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 677, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 728, in exec_module File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed File "/Users/AKIKO/Desktop/django_app/django_app/urls.py", line 21, in <module> path('hello/',include('hello.urls')), File "/opt/anaconda3/envs/myspace/lib/python3.7/site-packages/django/urls/conf.py", line 34, in include urlconf_module = import_module(urlconf_module) File "/opt/anaconda3/envs/myspace/lib/python3.7/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1006, in _gcd_import File "<frozen importlib._bootstrap>", line 983, in _find_and_load File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 677, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 728, in exec_module File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed File "/Users/AKIKO/Desktop/django_app/hello/urls.py", line 17, in <module> from .views import HelloView File "/Users/AKIKO/Desktop/django_app/hello/views.py", line 4, in <module> from .forms import HelloForm File "/Users/AKIKO/Desktop/django_app/hello/forms.py", line 3, in <module> class HelloForm(forms.Form): File "/Users/AKIKO/Desktop/django_app/hello/forms.py", line 4, in HelloForm check=forms.BoolenField(label='Checkbox',required=False) AttributeError: module 'django.forms' has no attribute 'BoolenField'
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/05/05 03:47