質問編集履歴

1

コードの追加

2019/10/03 02:39

投稿

omyu
omyu

スコア22

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