teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

コードの追加

2019/10/03 02:39

投稿

omyu
omyu

スコア22

title CHANGED
File without changes
body CHANGED
@@ -1,5 +1,85 @@
1
1
  djangoでのアプリ製作中にTypeErrorが起きたのですが、どこが間違っているのかわかりません。
2
2
  プログラミング初心者で初歩的すぎる質問かもしれませんが、どなたか教えていただければ有り難いです。
3
+ > TypeError at /register/
4
+ AddressModelForm.Meta.fields cannot be a string. Did you mean to type: ('address',)?
5
+ Request Method: GET
6
+ Request URL: http://127.0.0.1:8000/register/
7
+ Django Version: 2.2.5
8
+ Exception Type: TypeError
9
+ Exception Value:
10
+ AddressModelForm.Meta.fields cannot be a string. Did you mean to type: ('address',)?
11
+ Exception Location: /usr/local/lib/python3.7/site-packages/django/forms/models.py in __new__, line 235
12
+ Python Executable: /usr/local/opt/python/bin/python3.7
13
+ Python Version: 3.7.3
14
+ Python Path:
15
+ ['/Users/takaharaomi/Desktop/myapp/weathermail',
16
+ '/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python37.zip',
17
+ '/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7',
18
+ '/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload',
19
+ '/usr/local/lib/python3.7/site-packages']
20
+ Server time: Thu, 3 Oct 2019 02:30:40 +0000
21
+
22
+ ```python3
23
+ from django.db import models
24
+
25
+ # Create your models here.
26
+ class AddressModel(models.Model):
27
+ address = models.CharField(max_length=100)
28
+ def __str__(self):
29
+ return self.address
30
+ ```
31
+ 上のがmodels.pyです
32
+ ```html
33
+ <!doctype html>
34
+ <html lang="ja">
35
+ <head>
36
+ <!-- Required meta tags -->
37
+ <meta charset="utf-8">
38
+ <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
39
+
40
+ <!-- Bootstrap CSS -->
41
+ <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">
42
+
43
+ <title>Register</title>
44
+ </head>
45
+ <body>
46
+ {% block content %}
47
+ {% endblock content %}
48
+
49
+ <!-- Optional JavaScript -->
50
+ <!-- jQuery first, then Popper.js, then Bootstrap JS -->
51
+ <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
52
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
53
+ <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
54
+ </body>
55
+ </html>
56
+ ```
57
+ 上のはbase.htmlです
58
+ ```html
59
+ {% extends 'base.html' %}
60
+
61
+ {% block content %}
62
+ <form action="" method="POST">
63
+ {{ form.as_p }}
64
+ <input type="submit" value="登録する">
65
+ </form>
66
+ {% endblock content %}
67
+ ```
68
+ 上のはregister.htmlです
69
+ ```python3
70
+ from django.shortcuts import render
71
+ from django.views.generic import CreateView
72
+ from .models import AddressModel
73
+
74
+
75
+ # Create your views here.
76
+
77
+ class Register(CreateView):
78
+ template_name = 'register.html'
79
+ model = AddressModel
80
+ fields = ('address')
81
+ ```
82
+ 上のはviews.pyです
3
83
  ![イメージ説明](1ea42f9cbf3b230f8c738b054b00eb13.png)
4
84
  ![イメージ説明](a2044b3014b9dcfabf518f138e47e88c.png)
5
85
  ![イメージ説明](f6d2f883c1062f0caa9f842f56e3c8c0.png)