djangoでのアプリ製作中にTypeErrorが起きたのですが、どこが間違っているのかわかりません。
プログラミング初心者で初歩的すぎる質問かもしれませんが、どなたか教えていただければ有り難いです。
TypeError at /register/
AddressModelForm.Meta.fields cannot be a string. Did you mean to type: ('address',)?
Request Method: GET
Request URL: http://127.0.0.1:8000/register/
Django Version: 2.2.5
Exception Type: TypeError
Exception Value:
AddressModelForm.Meta.fields cannot be a string. Did you mean to type: ('address',)?
Exception Location: /usr/local/lib/python3.7/site-packages/django/forms/models.py in new, line 235
Python Executable: /usr/local/opt/python/bin/python3.7
Python Version: 3.7.3
Python Path:
['/Users/takaharaomi/Desktop/myapp/weathermail',
'/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python37.zip',
'/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7',
'/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload',
'/usr/local/lib/python3.7/site-packages']
Server time: Thu, 3 Oct 2019 02:30:40 +0000
python3
1from django.db import models 2 3# Create your models here. 4class AddressModel(models.Model): 5 address = models.CharField(max_length=100) 6 def __str__(self): 7 return self.address
上のがmodels.pyです
html
1<!doctype html> 2<html lang="ja"> 3 <head> 4 <!-- Required meta tags --> 5 <meta charset="utf-8"> 6 <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> 7 8 <!-- Bootstrap CSS --> 9 <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"> 10 11 <title>Register</title> 12 </head> 13 <body> 14 {% block content %} 15 {% endblock content %} 16 17 <!-- Optional JavaScript --> 18 <!-- jQuery first, then Popper.js, then Bootstrap JS --> 19 <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script> 20 <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script> 21 <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script> 22 </body> 23</html>
上のはbase.htmlです
html
1{% extends 'base.html' %} 2 3{% block content %} 4<form action="" method="POST"> 5 {{ form.as_p }} 6 <input type="submit" value="登録する"> 7</form> 8{% endblock content %}
上のはregister.htmlです
python3
1from django.shortcuts import render 2from django.views.generic import CreateView 3from .models import AddressModel 4 5 6# Create your views here. 7 8class Register(CreateView): 9 template_name = 'register.html' 10 model = AddressModel 11 fields = ('address')
回答1件
あなたの回答
tips
プレビュー