您好,提前谢谢您。
我知道这完全是菜鸟问题,我已经在各种论坛中搜索并阅读并重新阅读了文档,所以请温柔。
我有一个看法:
#views.py
from django.shortcuts import render_to_response
from django.shortcuts import render
from django.http import HttpResponse, HttpRequest, HttpResponseRedirect
from acme.acmetest.models import Player
from acme.acmetest.models import PickForm
def playerAdd(request, id=None):
form = PickForm(request.POST or None,
instance=id and Player.objects.get(id=id))
# Save new/edited pick
if request.method == 'POST' and form.is_valid():
form.save()
return HttpResponseRedirect('/draft/')
#return render_to_response('makepick.html', {'form':form})
return render(request, 'makepick.html', {'form':form})
def draftShow(request):
draft_list = ['1', 'hello', 'test', 'foo', 'bar']
#draft_list = Player.objects.all()
#return render_to_response('makepick.html', {'draft_list' :draft_list}, context_instance=RequestContext(request))
return render_to_response('makepick.html', {'draft_list' :draft_list})
我试图让它呈现到模板 .html 页面:
#makepick.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<HTML lang="en">
<head>
<title>Pick</title>
</head>
<body>
<form method="POST" action="">
{% csrf_token %}
<table>{{ form }}</table>
<input type="submit" value="Draft Player"
</form><br /><br />
Your picks so far:<br />
{% for draft in draft_list %}
{{ draft.playernumber }}
{% endfor %}
</body>
</HTML>
其中 playernumber 是 models.py 中模型类“Player”中的字段。
#urls.py
from django.conf.urls.defaults import patterns, include, url
from acme.acmetest import views
urlpatterns = patterns('',
('^$', 'acme.acmetest.views.playerAdd'),
)
感谢您的帮助!
dp