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

質問編集履歴

1

index.html forms.py のコードを追加しました。

2021/02/06 00:46

投稿

iphone
iphone

スコア9

title CHANGED
File without changes
body CHANGED
@@ -241,4 +241,40 @@
241
241
 
242
242
  どのファイルを共有すればいいのかわかりませんので、
243
243
 
244
- 他のファイルを閲覧確認される場合、質問お願いします。
244
+ 他のファイルを閲覧確認される場合、質問お願いします。
245
+
246
+
247
+ **index.htmlコード**
248
+ ```index.html
249
+ {% extends 'carbike/base.html' %}
250
+ {% block title %}車・バイク推定アプリメニュー{% endblock %}
251
+
252
+ {% block content %}
253
+ <div>
254
+ <h4 class="mt-4 mb-5 border-bottom"車・バイクの推定アプリ>
255
+ <p>画像ファイルを選択して推定ボタンをクリックしてください。</p>
256
+ <form action = "{% url 'carbike:predict' %}" method="post" class = "form" enctype = "mutipart/form-data">
257
+ {% csrf_token %}
258
+ <div class="form-group">
259
+ <div class= "custom-file">
260
+ {{ form.image }}
261
+ <label class="custom-file-label" for="customFile">
262
+ 推定したいファイルを選択してください
263
+ </label>
264
+ </div>
265
+ </div>
266
+ <button type="submit" class="btn btn-primary">推定する!</button>
267
+ </from>
268
+ </div>
269
+ {% endblock %}```
270
+
271
+
272
+ ```
273
+
274
+ **forms.pyコード**
275
+ ```python:forms.py
276
+ from django import forms
277
+
278
+ class PhotoForm(forms.Form):
279
+ image = forms.ImageField(widget=forms.FileInput(attrs={'class':'custom-file-input'}))
280
+ ```