textファイルの中に入力した数字があるかどうか調べたいです。
id.txtに
100,300,500,800,200
と書きました。
index.htmlに
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>入力ページ</title> </head> <body> <form method="post" action="response"> <p>id:<input type="text" name="id"></p> <input type="submit" value="送信する"> </form> </body> </html>
と書きました。このindex.htmlにアクセスして、formタグのinputのidにid.txtに
存在する値を入力すると、入力した値が帰ってきて、id.txtに
存在しない値を入力すると0が帰ってくるシステムを作りたいです。
inputされた値とid.txtの値が一致するか調べるにはどのようなアルゴリズムを書けばいいのでしょうか?
views.pyには
from django.shortcuts import render # Create your views here. def index(request): user_id_form = UserIDForm(request.POST or None) context = { 'user_id_form': user_id_form, } return render(request, 'index.html', context) def response(request): return render(request, 'response.html')
と書き、
forms.pyには
from django import forms from .models import User class UserIDForm(forms.ModelForm): id = forms.IntegerField() class Meta: model = User fields = ('id',)
と書きました。models.pyには
from django.db import models # Create your models here. class UserIDForm(models.Model): id = models.IntegerField(max_length=100,null=True)
と書きました。どのように目的のアルゴリズムを書けばよいのでしょうか?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2017/10/30 07:31
2017/10/30 07:42
退会済みユーザー
2017/10/30 07:45