2017-11-09 16 views
0

私はDjangoを初めて使い、ユーザ入力のテキストを表示しようとしています。私は複数のことを試みましたが、これまでに何も働いていません。アドバイス/ヘルプが必要!ユーザの入力をdjangoに表示できません

models.py

from django.db import models 

class Post(models.Model): 
    message = models.TextField(max_length=4000) 

def __unicode__(self): 
    return self.title 

views.py

from .models import Post 
from django.core.exceptions import * 

def index(request): 
    return render('index.html') 

def result(request): 
    p = request.POST['message'] 
    return render_to_response('result.html', {'message': p}, context_instance=RequestContext(request)) 

index.htmlを

<!DOCTYPE html> 
<head> 
    <title>Index page</title> 
</head> 
<body> 
    <div id="header">Welcome to index page</div> 
    <div id="content"> 
     <p>Enter your name</p> 
     <form action="/polls/results.html/" method="post" accept-charset="utf-8">{% csrf_token %} 
      <input type="text" name="message"> 
      <input type="submit" value="Send!"> 
     </form> 
    </div> 
</body> 

results.html

<!DOCTYPE html> 
<head> 
    <title>Result page</title> 
</head> 
<body> 
    <div id="header">Here is the result</div> 
    <div id="content"> 
     <p>Your name is: {{ message }}</p> 
    </div> 
</body> 
: はここに私のファイルです

url.py

from django.conf.urls import include, url 
from django.conf.urls.static import static   
from . import views 

app_name = 'polls' 
urlpatterns = [ 
    url(r'^$', views.result, name='results'), 
] 
+0

フォームアクションが間違っているので、あなたのURLファイルを追加してください。 –

+0

ああ、はい。 url.pyが追加されました。 – sainidad

答えて

0

編集{% url 'result' %}にフォームのアクションので、これはURLを生成します

このような
<form action="{% url 'result' %}" ....> 
.... 
.... 
</form> 

だろう、あなたはURLをハードコーディングし、それがあまりにもドン我々間違っていました)

関連する問題