0
저는 장고를 처음 사용하고 사용자 입력 텍스트를 표시하려고합니다. 여러 가지 시도했지만 지금까지 아무것도 작동하지 않았습니다. 조언/도움 필요!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'),
]
양식 작업이 잘못되었습니다. URL 파일을 추가하십시오. –
오, 예. url.py가 추가되었습니다. – sainidad