フォームで入力された値を元にHTMLに表示させたりメソッド内で引数として使いたいのですが
python
1#forms.py 2from django import forms 3class MyForm(forms.Form): 4 text = forms.CharField(max_length=100) 5
python
1#views.py 2def form_test(request): 3 if request.method == "GET": 4 d = MyForm(request.GET) 5 if form.is_valid(): 6 return render(request,'note/result.html',{'d':d,},) 7 else: 8 form = MyForm() 9 return render(request, 'note/form.html', {'form': form,})
html
1form.html 2{% extends "note/base.html" %} 3{% block content %} 4<form action="" method="get"> 5 {{ form }} 6 <input type="submit" value="送信"> 7</form> 8{% endblock %}
html
1result.html 2{% extends "note/base.html" %} 3{% block content %} 4 <p>Hi there!</p> 5 {{d}} 6 <p>It works!</p> 7{% endblock %} 8
という形でコードを書いたのですが実際にフォームに文字列を入力してみると
のように検索フォームごと表示されてしまいます
引数としても使いたいと思っているので入力された文字列そのもののみ使いたいと思っているのですがどうすれば良いのでしょうか
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。